I have a QTreeWidget
and I want children of a QTreeWidgetItem
not indent when I expand them. I want to set the line only for top items. The first screenshot demonstrates what I would like to have, and the second what I am currently having. Would you please help me with how to change it to be like the first one? Thank you in advance!
Asked
Active
Viewed 2,075 times
3

László Papp
- 51,870
- 39
- 111
- 135

mari
- 417
- 1
- 6
- 21
-
Nothing is better than good old `file:///home/` link ;) – j_kubik Mar 08 '14 at 08:45
-
yes, sry, i edit it :D – mari Mar 08 '14 at 08:48
-
You can use http://qt-project.org/doc/qt-4.8/qtreeview.html#indentation-prop to control indentation, but you cannot do it with specific elements, ie. you cannot set zero indentation to only leaf items, leaving others indented. I don't think you can do it with regular `QTreeWidget`. – j_kubik Mar 08 '14 at 08:51
2 Answers
0
This is not possible by QTreeWidget
since you can only set the indentation globally. You would need to create your own class implementing this logic, e.g. QListWidgets
connected to each other, or just a brand new tree widget implementation. You could also of course improve the existing QTreeWidget and send a patch.

László Papp
- 51,870
- 39
- 111
- 135
-
i want to implement my own qtreewidget, but i dont know how to change toplevelitems and their subchilds indentation or how to set line only for top level items, would you please help me how can i do it? – mari Mar 08 '14 at 11:11
0
I found a workaround. Use QTreeView and in customized QStyledItemDelegate.paint(), make the sub-child item widget move slightly to the left.
def paint(self, painter, option, index):
self.initStyleOption(option, index)
# top-level item
if index.parent().isValid() == False:
return super().paint(painter, option, index)
# sub-child item
item = index.model().itemFromIndex(index)
item_widget = any_method_to_get_your_subchild_widget()
item_widget.setGeometry(option.rect.adjusted(-1*option.widget.indentation(), 0, 0, 0))
item_widget.show()
pass

funway
- 113
- 1
- 7