[Qt-interest] Question about Models, Roles and data

Andre Somers andre at familiesomers.nl
Wed Aug 26 08:28:44 CEST 2009


Murphy, Sean M. wrote:
> Or maybe there is a way that my one current model builds up all the
> fields of all objects, but I can somehow only show the first column in
> my description-only tree view?  The only problem I see there is that my
> Foo and Bar objects have a different number of data fields, which would
> result in a different number of columns - I don't know if that matters
> or not.
>   
Did you see the QTreeView::hideColumn() method? It allows you to hide 
the columns in the views where you don't want them. Alternatively, you 
could create a simple proxy model that hides the columns for you.
It is no problem for your table views if the foos and bars have a 
different number of columns. See QAbstractItemModel::columnCount(). Do 
you see the parent argument in that method? You can determine by the 
parent model index what kind of object you are dealing with, and return 
the correct number of columns for your item.

Good luck!

André







More information about the Qt-interest-old mailing list