Results 1 to 5 of 5

Thread: Table view with collapsible rows

  1. #1
    Join Date
    Sep 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Table view with collapsible rows

    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/j...ablesorter.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.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Table view with collapsible rows

    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)

  3. #3
    Join Date
    Sep 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Table view with collapsible rows

    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)

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Table view with collapsible rows

    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.

  5. #5
    Join Date
    Sep 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Table view with collapsible rows

    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.

Similar Threads

  1. Trouble coloring table view rows
    By waynew in forum Qt Programming
    Replies: 11
    Last Post: 30th August 2010, 15:38
  2. Replies: 5
    Last Post: 3rd April 2010, 05:07
  3. Replies: 4
    Last Post: 26th October 2009, 23:25
  4. Refreshing one or more rows in a table view
    By William Wilson in forum Qt Programming
    Replies: 4
    Last Post: 25th May 2009, 01:10
  5. How to set two rows in a table view Horizontal header?
    By sivollu in forum Qt Programming
    Replies: 11
    Last Post: 29th April 2009, 05:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.