PDA

View Full Version : Styling a branch in QTreeView depending on an additional property



Debilski
29th October 2009, 13:13
Hello,

I’m using a QTreeView where the branches can be updated seperately. Anytime, a branche updates, it should not be possible to expand the branch, so I want to replace the + or arrow icon with something else. My first approach was to use a user-defined property on the ItemDelegate, however this only works with the item’s icon and not with the branch’s.

So, I’d like to know if it is possible to make the style used for a branch icon dependent on an additional property. I know, that it is possible with style sheets to use properties like active and children and so on, but can I define some other property for the branch without cloning all but one line of QTreeView::drawBranches? (Unfortunately the extraFlags variable used inside drawBranches is not directly assignable from the outside, and on the other hand, drawPrimitive does not take any information about the QModelIndex but maybe there is some trick to get this working.)

/rike

wysota
29th October 2009, 16:32
You can draw the branch yourself. It's done by reimplementing QTreeView::drawRow() as far as I remember.

Debilski
2nd November 2009, 13:24
I think, I’ve found some kind of work around to this problem. Since QTreeView::drawBranches() takes the QModelIndex as an argument, I can subclass this method and then draw the icon inside that, if needed. It still needs a bit of fine-tuning, though.