[Qt-interest] Question about Models, Roles and data
André Somers
andre at familiesomers.nl
Tue Aug 25 20:16:22 CEST 2009
Hi,
-----Oorspronkelijk bericht-----
Van: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] Namens Arnold Krille
Verzonden: dinsdag 25 augustus 2009 19:24
Aan: qt-interest at trolltech.com
Onderwerp: Re: [Qt-interest] Question about Models, Roles and data
>> For the table that shows all the data fields of all the bars, you may
>> need to build a new model (so, the answer changes to two, sorry!), as
>> you would be changing parent/child relationships here.
>
>No, a table is actually a tree with only first-level entries:-) In other
words: A tree-model can have as many columns >as needed, the QTreeView or
any simpler QTableView (showing only foos or bars) will show the columns.
I know, but if I understand the question correctly, the OP wanted to show
only _second_ level entries. Now that may be a problem... AFAIK a QTableView
can actually operate on any level, not just the first level (just like
QListView can).
>> If you want to
>> cheat, you might be able to hide your foo classes from the view with a
>> custom delegate, but that may not be the best approach...
>
>Don't do that. If you want to hide the foos, use a proxymodel. A delegate
is for the presentation (and user->interaction), not for data-modification.
I know, I know. Can you really hide top-level nodes with a proxy model
though while still showing the second level nodes though? I've never tried
to do that, but I guess it would not be easy.
> And stay away from custom roles unless you really have to use them.
> The main advantage of model-view is that you can plug (almost) any view on
any model and it makes sense,
> preferable without using custom delegates. If you need custom roles, you
loose all that...
Well, it's not that bad to use them. You still have nicely working views.
You can just get more data when you need it, like in a slot that acts on an
item in your view being selected. That may be very usefull.
André
More information about the Qt-interest-old
mailing list