PDA

View Full Version : How to create QStandardItem with two checkboxes in QTreeView



topoden
16th April 2010, 19:54
Hi gus,

I still do not believe that I could not find the answer for the question in the forum history... I though it was quite normal case...
:confused:

So the question actually is how can I create QTreeView where every node has two check boxes (it does not have to be QStandardItem based, but prefferable as I'm already using it in my program).

I could add one more column into the QTreeView and put the second check box in there but in this case the second check box will be visually located in a different column (aligned by that column). I want the second check box to be displayed right next to the first one (indented in the same way as the first check box)

Thank you very much for your help in advance !

faldzip
16th April 2010, 22:59
I would implement custom delegate where I would draw checkboxes with QStyle or QStylePainter and implement clicking on it in QAbstractItemDelegate::editorEvent(). I would not implement highlight on mouse hover, because it will be more complicated and is not necessary. Of course check state of those checkboxes would be stored in model, not necessarily in Qt::CheckStateRole only as there are 2 checkboxes. And then I would use this delegate only in this one column where it is needed so I wouldn't have to take care about other columns in delegate while implementing it.
That's my idea :]