Search code examples
c++qt5qwidgetqtreeviewqstyle

How to get identation width of QTreeView from QStyle


I have pre-existing code which has a tree view like appearance but doesn't actually use QTreeView (uses QListWidget with custom paint).

I am tasked to add the indentation between the parent and child objects, but I can't able to find how to get the style default indentation width from QStyle. The program has to run on a variety of os and allow to use custom stylesheets. So it's important to get this option from QStyle.

Regards.


Solution

  • found this in qt sources

    have to use QStyle::pixelMetric with QStyle::PM_TreeViewIndentation
    inside your widget's procedure

    ident = style()->pixelMetric(QStyle::PM_TreeViewIndentation)