[Interest] Grouping Items in TreeWidget

André Somers andre at familiesomers.nl
Wed Nov 20 10:36:27 CET 2013


Joseph W. Joshua schreef op 20-11-2013 9:40:
> Hi all,
>
> In the attached image, you can see how I am able to group items in a 
> listview in .NET. Is there a way to achieve this in Qt? I have tried 
> several avenues with no apparent success. 
Sure, this is doable, but it takes a little work.

You're going to need a delegate to render your header items. You make 
the delegate return a sizehint for the item (to get the extra height). 
You can make it draw the underline, and if you want you can also make it 
do the column spanning, though that's a bit trickier. It might be easier 
to use QTreeView::setFirstColumnSpanned for that, even though that 
breaks the model/view pattern.*

André

[*] I don't get why QAbstractItemModel::span was never actualy used in 
Qt. I had to write my own delegate that uses it to get it to work.



More information about the Interest mailing list