PDA

View Full Version : QTreeWidget & QStyle::PE_IndicatorBranch



nakkore
15th November 2006, 20:32
Hi,
as far i saw the default behaviour for QTreeWidget when adding a topLevelItem is not showing the branch indicator (the item to expand or collapse the subtree) if this item has no child.
Now i want to show an indicator even if the topLevelItem has no child.
I've played around subclassing QStyle and implementing drawElement to handle the case of a PE_IndicatorBranch. The problem is that i'm not able to decide in drawElement if the item processed is a topLevelItem or a child item. I've tryed to obtain this information looking at state() and QStyle::StateFlag but i'm not able to obtain the desidered behaviour.
Can anyone help me showing me some actual code ? or a way to solve this problem ?

Thanks in advance.
Giorgio

jpn
16th November 2006, 07:53
The QStyleOption parameter indeed delivers all the information including, amongst the others, whether the index has children and whether it's expanded or collapsed. However, there is no way in a style to know if it's a top level index in question.

You could try to override QTreeView::drawBranches(). That's where the QStyle::drawPrimitive(PE_IndicatorBranch) is called from. You could then try to pass a custom combination of state flags in case it is a top level item.

nakkore
16th November 2006, 21:51
Thank you for reply, i solved the problem overriding , as you suggested, drawBranch using the QModelIndex parameter and model() to get more info from the tree.
G.