PDA

View Full Version : Delegate for a certain item?



somebody
18th August 2008, 23:47
Hello!

I'm trying to implement something similar what you can see here http://crunchbang.org/uploads/103007035559-tracker.gif.

But below the category rows (gray background) should be a treeview.

I started to use a TreeView for all that stuff. That is, my first level children (deep 1) are the categories (gray row). Therefore I used setFirstColumnSpanned() of the tree view for these rows. Now I wanted to highlight these category rows with a different background similar to the screenshout. I created a delegate.

The problem is: How can I say that the delegate only should be used for the category item?

setItemDelegate() will setup the delegate for all items
setItemDelegateForRow() will setup the delegate for ALL items of a certain row (but independant of the level! that is, also in a deep level I would have the delegate because the row number matches)


Writing this an other idea comes to my mind. I could use the same delegate for all items, but in the paint() method of the delegate I would just look wheter the model index is from the first level. But this would'nt be that efficient?

Is there another way? What about a vertical layout and every second row (of this layout!) is a treeview widget. The other rows are categories...some custom widget. But in the end the category rows should be clickable, so that the treeview can be hidden. And drag and drop between the rows should also be possible etc...

Another related problem: how to hide the branches (and the small clickable stuff for expanding) only for the first level?

Any hint how to proceed? :)

wysota
18th August 2008, 23:55
Basically you have two choices - either make the delegate colour-aware or make the model colour-aware. For the latter simply make your model return a different colour (gray) for Qt::BackgroundRole of top-level items. If you want to implement it in the delegate, simply apply the delegate to the whole view (setItemDelegate(...)) and in the paint() routine check if the parent index is valid. If it is not, it means the item is a top-level item.