Results 1 to 2 of 2

Thread: How to map a table model to a tree with QAbstractProxyModel?

  1. #1
    Join Date
    Apr 2009
    Posts
    1
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows

    Default How to map a table model to a tree with QAbstractProxyModel?

    As the title says, I have a model class derived from QAbstractTableModel. I can display it correctly on a QTableView or QListView. However, whenever I try to make a proxy model to display it in a QTreeView I either end up doing some pretty nasty stuff (like, keeping the row number of a model as internalId, assigning different Ids to the 'virtual nodes so I can distinguish them etc). At the end, I usually end up not using the MVC at all because of this. I have tried many times to make a good clean solution at no avail.
    So, what I need is this. Let's say I have a table model with columns like this (pretty simplified though):

    id | first_name | last_name | city | job_position

    now, I sometimes need to display it in a table, or a list which is fine. But many times I need to display it in a tree, where the cities will be top nodes and will contain everyone in that city. Or maybe the job positions will be as top nodes. You get the idea. I've been looking for a clean solution to this all over and decided to post it here before going back to not using MVC in the current project. I hope someone can help here.

    Thank you

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to map a table model to a tree with QAbstractProxyModel?

    There's something similar to this in the history management of the browser example. It is also described briefly here: http://labs.trolltech.com/blogs/2008...-of-modelview/

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

    l034n (11th June 2010)

Similar Threads

  1. Replies: 33
    Last Post: 7th December 2009, 10:11
  2. A simple example of a tree model
    By YaK in forum Qt Programming
    Replies: 2
    Last Post: 4th March 2009, 17:15
  3. QAbstractProxyModel to do a Tree
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 18th November 2008, 17:31
  4. using the example of simple tree model
    By krishna.bv in forum Qt Programming
    Replies: 1
    Last Post: 22nd December 2006, 12:28
  5. Replies: 4
    Last Post: 11th September 2006, 14:13

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.