Results 1 to 2 of 2

Thread: Displaying QAbstractItemModel in a Table

  1. #1
    Join Date
    Feb 2006
    Posts
    32
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Question Displaying QAbstractItemModel in a Table

    Hello

    I have a hierarchical QAbstractItemModel. For this model, I want to display all the items which are not at the top level in a simple list.

    The Model:
    Qt Code:
    1. parent1
    2. +- child11
    3. +- child12
    4. parent2
    5. +- child21
    6. parent3
    7. +- child31
    To copy to clipboard, switch view to plain text mode 
    should be displayed as:
    Qt Code:
    1. child11
    2. child12
    3. child21
    4. child31
    To copy to clipboard, switch view to plain text mode 

    I have tried to accomplish this by displaying the model in a QTableView, but this displays only the parent items. I have also tried to display the model in a QTreeView and hiding the parents, but unfortunately hiding the parent items does also hide their children.

    Is there a way to do this except for writing a completly new view class? Perhaps subclassing QTreeView or QTableView in a smart way?

    Any help would be appreciated.

    Regards Ben

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Displaying QAbstractItemModel in a Table

    Quote Originally Posted by aqualoom View Post
    Is there a way to do this except for writing a completly new view class? Perhaps subclassing QTreeView or QTableView in a smart way?
    Try implementing a proxy model. There's an example of a Transpose Proxy Model in our wiki. It doesn't do at all what you want but gives you a simple idea how proxy models are implemented. What you should do is to map the children as top level indices.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:


Similar Threads

  1. Delegates and Table
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 18th May 2006, 19:47
  2. displaying any table on a qdatatable
    By Philip_Anselmo in forum Newbie
    Replies: 4
    Last Post: 9th May 2006, 22:12
  3. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:50
  4. Adding row in a Table after selected row
    By ankurjain in forum Qt Programming
    Replies: 3
    Last Post: 20th April 2006, 18:06
  5. Table model / view editing issue
    By Caius Aérobus in forum Qt Programming
    Replies: 9
    Last Post: 7th April 2006, 11:03

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.