Results 1 to 3 of 3

Thread: Using a TreeModel with a treeView and tableView

  1. #1
    Join Date
    Sep 2010
    Posts
    3
    Qt products
    Qt4

    Default Using a TreeModel with a treeView and tableView

    I have a TreeModel that is displayed in a tree View. I also have a proxyModel that sets its source to the TreeModel and then gets displayed in a table view. The problem I am having is only the parent nodes are getting displayed in the table view.

    My tree looks like the following:

    parent1
    | |_Child1_1
    | |_Child1_2
    |
    parent2
    | |_Child2_1
    | |_Child2_2
    |
    parent3

    My table looks like:
    parent1
    parent2
    parent3

    I would like to have it look like:

    parent1
    Child1_1
    Child1_2
    parent2
    Child2_1
    Child2_2
    parent3

    Here is a brief snipit of how I set everything up
    Qt Code:
    1. TreeModel *model = new TreeModel(headers, file.readAll());
    2. treeView->setModel(model);
    3.  
    4. mProxyModel = new MySortFilterProxyModel(model);
    5. mProxyModel->setDynamicSortFilter(true);
    6. mProxyModel->setSourceModel(model);
    7.  
    8. this->tableView->setModel(mProxyModel);
    9. this->tableView->setSortingEnabled(true);
    10. this->tableView->sortByColumn(0, Qt::AscendingOrder);
    To copy to clipboard, switch view to plain text mode 

    Does anyone know how I can go about displaying the children nodes in the table?

  2. #2
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using a TreeModel with a treeView and tableView

    you need use a proxy model for "flatness" the tree model.

    create a subclass of QAbstractProxyModel, and reimplement the funcion parent() to redirect the parent of child nodes to the rootIndex() instead of the original parent, remember you need to reimplement all the virtual function of QAbstractProxyModel




    also check the link http://doc.trolltech.com/4.5/model-view-model.html
    and the example of a transpose proxy model http://www.qtcentre.org/wiki/index.p...se_proxy_model


    PS. sorry my poor skills using paint
    Last edited by ecanela; 25th September 2010 at 07:03.

  3. #3
    Join Date
    Sep 2010
    Posts
    3
    Qt products
    Qt4

    Default Re: Using a TreeModel with a treeView and tableView

    I am a bit confused on how to reimplement parent() any tips?

Similar Threads

  1. Replies: 2
    Last Post: 7th September 2010, 08:38
  2. Replies: 3
    Last Post: 12th July 2010, 13:12
  3. About TreeModel and TreeItem?
    By yangyunzhao in forum Qt Programming
    Replies: 2
    Last Post: 14th August 2009, 07:25
  4. updating treeview from tableview
    By darshan in forum Qt Programming
    Replies: 4
    Last Post: 11th February 2009, 19:53
  5. TreeView, TableView
    By rbrand in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2006, 08:54

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.