Results 1 to 4 of 4

Thread: treeview with multiple models

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default treeview with multiple models

    I would like to concatenate multiple models into one tree view. When an index is selected in this treeview, I would like to be able to know what 'sub'model was selected and what index of that 'sub'model was selected.

    Qt Code:
    1. # example data
    2. Model1
    3. data1
    4. child 1
    5. child 2
    6.  
    7. Model2:
    8. data2
    9. child 1
    10. child 2
    11.  
    12. Treeview:
    13. data 1
    14. child 1
    15. child 2
    16. data 2
    17. child 1
    18. child 2
    To copy to clipboard, switch view to plain text mode 

    Purpose: If I clicked on child 2 of data 2, I would like to be able to call setModel(Model2) and setRootIndex(???) on a QTableView which I have set up as an editor.


    If I implement a proxy view, what modifications do I need to make? See below:


    Qt Code:
    1. QSortFilterProxy or QAbstractProxyModel?
    2.  
    3. data(): how do I know which model was clicked?
    4. index(): how do I know which model to use?
    5. parent(): ?
    6. mapToSource(): ?
    7. mapFromSource(): ?
    8. rowCount(): sum of rowCount from all models
    9. columnCount(): 1
    To copy to clipboard, switch view to plain text mode 

    I'm thinking the key is in mapToSource/mapFromSource and having to count what row your on. Eg: If Model 1 has 10 rows and you are on row 12, and Model 2 as 10 rows, then you are requesting row 2 from model 2. Is this how it's done or is there a more elegant approach?

    TYVM,

    BB
    Last edited by BreakBad; 24th July 2012 at 22:31.

Similar Threads

  1. QTreeView and multiple models
    By Daher in forum Qt Programming
    Replies: 3
    Last Post: 3rd December 2019, 20:57
  2. QTreeView with multiple QDir models
    By papillon in forum Qt Programming
    Replies: 3
    Last Post: 11th November 2011, 23:23
  3. QTreeView with multiple models
    By Daher in forum Qt Programming
    Replies: 5
    Last Post: 18th October 2011, 10:53
  4. View using multiple models
    By johnmauer in forum Qt Programming
    Replies: 13
    Last Post: 5th October 2010, 18:28
  5. QSortFilterProxyModel with multiple source models
    By hoshy in forum Qt Programming
    Replies: 1
    Last Post: 26th August 2009, 20:59

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.