Results 1 to 4 of 4

Thread: TreeModel from TableModel

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Default TreeModel from TableModel

    I need to create a tree model with the following req's

    • this tree model will have a flat table source (QAbstractTableModel)
    • hierarchy will be based on the sort columns
    • at the end of the day a QTreeView and this model will behave exactly like the new Outlook 2010 Inbox list , when the user click sort by date a tree will be presented grouped by date


    I am thinking is a job for a QSortFilterProxyModel and a CustomTreeModel that will goup things according to QSortFilterProxyModel::sortColumn and convert it into a tree in the QTreeView points of View.

    Is there any other good suggestions out there?

    baray98

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

    Default Re: TreeModel from TableModel

    QSortFilterProxyModel will not work as it cannot move an item to a different parent. You need to implement your own subclass of QAbstractProxyModel.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2007
    Posts
    275
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    28
    Thanked 2 Times in 2 Posts

    Default Re: TreeModel from TableModel

    CustomTreeModel will come handy which inherits QAbstractItemModel to wrap around the sortfilter model. The sort filter model will be used only for sorting and giving the sortColumn in which the grouping will be based upon..

    -baray98-

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

    Default Re: TreeModel from TableModel

    It needs to be done the other way round. The sort filter proxy model needs to wrap the tree (proxy) model. Otherwise sorting will not take into consideration the parent-child relationship of items.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 10th January 2011, 01:06
  2. Using a TreeModel with a treeView and tableView
    By sheik482 in forum Qt Programming
    Replies: 2
    Last Post: 27th September 2010, 03:25
  3. About TreeModel and TreeItem?
    By yangyunzhao in forum Qt Programming
    Replies: 2
    Last Post: 14th August 2009, 07:25
  4. Compiling qt tablemodel
    By jmqt in forum Newbie
    Replies: 2
    Last Post: 15th June 2009, 06:47
  5. Refresh TableModel
    By abbapatris in forum Qt Programming
    Replies: 8
    Last Post: 7th March 2008, 13:55

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
  •  
Qt is a trademark of The Qt Company.