[Interest] Make a flat Model from a hierarchical Model with all children

Bo Thorsen bo at fioniasoftware.dk
Wed Mar 28 11:50:43 CEST 2012

Den 28-03-2012 08:34, Andre Somers skrev:
> Op 28-3-2012 8:20, Bo Thorsen schreef:
>> Den 27-03-2012 14:01, André Somers skrev:
>>> Op 26-3-2012 18:34, j-p.nurmi at nokia.com schreef:
>>>>> I have a hierarchical Model and i want to have a flat Model.
>>>>> Does anyone have an idea on how to do this with an proxy model?
>>>> Try this:http://www.fioniasoftware.dk/blog/?p=51
>>> Interesting. Not sure why he (Bo) didn't just replace the view with a
>>> QTreeView though? Seems simpler...
>> Hehe, you're missing the next level - the view classes are not the
>> only ones that can use the models :) I use this to choose items in a
>> tree model with a combo box.
>> QComboBox can take a model to deliver the items in it. But tree models
>> have parents and usually multiple columns. The flat proxy can make a
>> single item with the text of each item based on several columns.
> No, I got that part. My point was (or was supposed to be) that QComboBox
> can also display a tree directly, if you use it's setView method and set
> a tree view there. For easy use, you'd only need to confine the tree to
> a single column, but the parent/child relationship does not need to be
> removed for that.

The problem is that if you have multiple columns in your tree, the 
treeview doesn't show each item as I want. It's IMHO pretty rare that 
you can just set the treeview on it and that the text shown makes sense. 
That's the reason the flat proxy doesn't just show something but that I 
can set the format on it. I use this to set stuff like "(accountnumber) 
accountname" for the combo box text. And setting a tree view won't let 
me do that.

Bo Thorsen,
Fionia Software.


Expert Qt and C++ developer for hire
Contact me if you need expert Qt help

More information about the Interest mailing list