Results 1 to 5 of 5

Thread: hierarchical model in a flat view

  1. #1
    Join Date
    Jun 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question hierarchical model in a flat view

    I have a hierarchical model (subclassed QAbstractItemModel) and want to display it in different itemviews. One of these views is a standard QTreeView. For another view I would like to display the hierarchical model as a flat model. With this I mean, I would like to display only leaf items (those that have no children) in either a QTableView or QListView.

    Does anyone know how to accomplish this? I do not want to make a new flat model class for this, because I want to use the same model and selection model between all views. I only want to view my hierarchical model as a flat leaf model.

    tnx in advance

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hierarchical model in a flat view

    As far as I understood the docs QAbstractProxyModel, once subclassed and used wisely, should fit your needs...
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: hierarchical model in a flat view

    Quote Originally Posted by fullmetalcoder
    As far as I understood the docs QAbstractProxyModel, once subclassed and used wisely, should fit your needs...
    Yes, I can confirm that. Subclass it and reimplement pure abstract methods. Just do it wisely, because you have to know all the leaves of the tree upfront. You might have to cache the data from the underlying model and connect to its signals to update the cache when the underlying model changes.

  4. #4
    Join Date
    Jun 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: hierarchical model in a flat view

    Yep, subclassing QAbstractProxyModel did the trick. Too bad I can't couple selectionModels anymore, because the models are different now. Now why isn't there a QAbstractProxySelectionModel class Oh well I guess I'll just have to make one myself.

  5. #5
    Join Date
    Oct 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: hierarchical model in a flat view

    Hi,

    I have a similar problem. Can you give any examples how to map tree model nodes for flat view? Simplest way would of course give a root index for a view but I would like to do it in proxy.

Similar Threads

  1. Model - View Programming doubt.
    By munna in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2006, 14:01
  2. Replies: 6
    Last Post: 20th April 2006, 11:23
  3. Model, view, resize to show all data
    By jcr in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2006, 21:59
  4. Table model / view editing issue
    By Caius Aérobus in forum Qt Programming
    Replies: 9
    Last Post: 7th April 2006, 12:03
  5. drag and drop with item views
    By castorvert in forum Qt Programming
    Replies: 14
    Last Post: 27th March 2006, 11:12

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.