PDA

View Full Version : Table view with collapsible rows



adith387
16th September 2010, 10:11
Hi, I am using QT4.6 and developing using QtCreator.
The data I have is arranged in a table having 7 columns (of which three columns have data which can only be one of a few values...like, say, Gender, or Nationality ).

I want to show this in a QtTableView (or, something that renders like a table) with sort capability. (I managed to reach upto this point using a QStandardItemModel and a QTableView).
However, I also want the following functionality :
for those three columns, I can "group" based on values ... for eg., this way, I get a summary of all rows whose gender is Male

QTreeview is not a good-looking option because it forces a hierarchy on the three columns, meaning, I will have to expand Gender, then Nationality in that fixed order. I cannot "regroup" in some sense.

In my mind, the finished view looks something like http://www.pengoworks.com/workshop/jquery/tablesorter/tablesorter.htm
(except when I uncollapse a row, I dont just get the shipping addresses, but a break-up of the total cost for each address, say).

Thanks in advance.

Lykurg
16th September 2010, 10:25
Your example is a QTreeView. It seems the right way to go, but I don't really understand what you exactly want to achieve. Could you be a little bit more elaborate with same simple example of your data. (especially what do you want to group and how should it look like)

adith387
16th September 2010, 12:53
Hi,

Lets say the table is as,

Gender \t Name \t Nationality \t Balance

Male \t Bob \t French \t +50
Male \t Rob \t American \t +20
Male \t Cobb \t American \t -10
Female \t Alice \t French \t -30
Female \t Mary \t American \t +50

Now, I would like the first view to be collapsed by default....say,

Gender \t Name \t Nationality \t Balance

Male \t \t \t +60
Female \t \t \t +20

Now, on uncollapsing Male (by any interactive event), I get,

Gender \t Name \t Nationality \t Balance

Male \t Bob \t French \t +50
Male \t \t American \t +10
Female \t \t \t +20

The thing is, from the completely uncollapsed table, I can generate a different grouping also, viz.

Gender \t Name \t Nationality \t Balance

\t \t American \t +60
\t \t French \t +20

I dont like the TreeView output, because, it forces a particular order of grouping .... I must force the user to open up the "Male" node, then the "Nationality" node, and finally click on a person to see balance. And, from a completely un-collapsed tree, it is not easy to see cumulative statistics for a different kind of grouping. I was hoping there was something intuitively responding like the SQL group by statements ... I have seen several such examples in JavaScript (Yahoo's YUI library has one built in)...but I wanted to use QT since my data has a real-time aspect to it, and standards suggested Qt was fast in these settings.

Thanks. (and sorry for the messy table output)

Lykurg
16th September 2010, 14:00
Ok, I see. But this is not a matter of the view than rather of the model. The model must provide the functionality of grouping. The view only displays the content of the model. If the model supports all actions you want, you have to connect the different view signals to the corresponding model slots which will alter the model data.

There is no ready to use solution in Qt for your requirement as far as I see.

See also QSortFilterProxyModel.

adith387
16th September 2010, 15:07
Oh, I got my hopes up after seeing the Hierarchical Header View.

QSortFilterProxyModel is what I tried (atleast, the filter part of it). Perhaps I should fight with it a little more.

Thanks, and if you know any code samples w.r.t QSortFilterProxyModel over and above the trolltech examples, it will be much appreciated.