5

Is it possible to have individual indentation of items in a QTreeWidget?

In specific, I have have a column containing both text, icon and for some of them a CheckBox. The items without a CheckBox gets shifted to the left so the indentation of the icon and the text is not inline with the others. Could maybe be fixed with a hidden CheckBox if that is possible?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Magus
  • 87
  • 1
  • 6

2 Answers2

0

You can try using the QWidget::setContentMargins() on the widget returned by QTreeWidget::itemWidget().

gregseth
  • 12,952
  • 15
  • 63
  • 96
  • Hi. Thanks a lot for your reply. Whenever I try to do something with the QWidget returned by QTreeWidget::itemWidget() my app crashes. Do you know why can happen? I dont call this before the item hierarchy is set up. – Magus Mar 03 '10 at 12:25
  • 1
    Oh, now you say that, I recall that `QTreeWidget::itemWidget()` returns a non `NULL` value only if the widget was set with `QTreeWidget::setItemWidget()`. To solve your problem I guess you have to create your own item displaying the icon and handlig the checkbox/extra-space. – gregseth Mar 03 '10 at 13:19
0

Maybe the use of Delegates will give you a nice and proper implementation. You'll have the opportunity to re-implement the paint() and sizeHint() methods, and therefore, choose the way your QTreeWidgetItem are being drawn...

More documentation here : http://doc.trolltech.com/4.6/model-view-delegate.html

An example : http://doc.trolltech.com/4.6/itemviews-pixelator.html

Hope it helps a bit !

Andy M
  • 5,945
  • 7
  • 51
  • 96
  • Hi, thanks a lot for your input. I'm currently not using the Model/view framework, just ordinary QTreeWidgetItems so I guess I cant uses the delegate approach here. But thanks! – Magus Mar 03 '10 at 12:21
  • You can use delegates with QTreeWidgetItems – Rafe Sep 22 '12 at 00:50