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

Murphy, Sean M. sean.murphy at gd-ais.com
Wed Aug 26 16:26:51 CEST 2009


> 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.

No, and I was actually looking for it!  I must have skimmed too fast, I
think I was looking for a set number of columns method, not a method
that hides individual ones.  Thanks for pointing that out!

I think the proxy model might be the right solution for the
description-only tree view that we want.  I think my model naturally
might want around 5 columns for the file object, about 10 columns for
the foo objects and around 20 columns for the bar objects, but for that
tree view, I'd only want to show the first column of each of the 3
classes.  So rather than hide 19 columns, it seems like it might be
easier to have a separate model that only builds up one column for that
one view?

> 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.

Ok, this one I'm not understanding what you mean.  I think you're
describing a method that I can still get by just using one model; that I
would not need to use a proxy?  If my one model naturally has different
numbers of columns, and I have several views I want to use with that one
model: one a tree view where I only show the first column of all
objects, and other table views where I show all columns of only one type
of object (so a 10 column table that shows only foo's or a 20 column
table that shows only the bar's for example), I don't quite see how I
set a table view to use my model, but only get foo's (or only bar's) to
pop out of it.

The bar only table that I want especially confuses me.  If this is the
file data structure (spaces delimit columns):

fileDescription fileData1 fileData2 ... fileData4
  foo1_Description foo1_Data1 ... foo1_Data9
    bar1_1_Description bar1_1_Data1 ... bar1_1_Data19
    bar1_2_Description bar1_2_Data1 ... bar1_2_Data19
  foo2_Description foo2_Data1 ... foo2_Data9
    bar2_1_Description bar2_1_Data1 ... bar2_1_Data19
  foo3_Description foo3_Data1 ... foo3_Data9
    bar3_1_Description bar3_1_Data1 ... bar3_1_Data19

I'd want my bar only table to show all 4 bar objects that are in the
file, regardless of which foo's they belong too.  So I should end up
with a 20 column table that looks like:
    bar1_1_Description bar1_1_Data1 ... bar1_1_Data19
    bar1_2_Description bar1_2_Data1 ... bar1_2_Data19
    bar2_1_Description bar2_1_Data1 ... bar2_1_Data19
    bar3_1_Description bar3_1_Data1 ... bar3_1_Data19

Thanks for all the help, I think I'm getting a glimmer of how powerful
these model/view classes can be, it just hasn't all clicked yet.  I'm
working my way through the
http://doc.trolltech.com/4.5/model-view-introduction.html documentation
in between these emails.

Sean




More information about the Qt-interest-old mailing list