Sync QTreeView selection with QTableView root



  • Hey forum.

    I'm struggling with this problem. I can't see how to achieve this.
    I have my model SoftModel.
    I have a QTreeView called SoftView with a Proxy which displays only first column.
    And I want a QListView or QTableView (called SoftOptions with a Proxy wich switch rows and columns ) which displays other columns depending on QTreeView first item selection.

    I noticed basic use of QModelIndex is unusable because it shows index in current item table.
    Basically, first item of a node have the same row and column of any other other node first item.

    So, how to set the root of my QTableView if all QModelIndex are "identical"?
    I figured createIndex with index(row, column, &QModelIndex) could be useful, but I really don't get how it works.

    Thanks for any help.



  • You will need to traverse your proxies in order to translate your current tree view selection to an index that matches the model your table view is presenting.



  • Thanks Andre. I was thinking of this method too.
    First, TreeView & TableView are sharing the same base model.

    I tried with mapToSource on TreeView's Proxy and mapFromSource on TableView Proxy, but nothing happens. :/

    I tried also to store each parent to RootNode in a QModelIndexList, from the QModelIndex selected. But I don't know how to apply this back to the TableView.

    Just to be sure, on the TableView, I do need to use setRootIndex for my goal?



  • Hey again Andre.
    To extend on my previous post, I'm also wondering if I should/can set the TableView root to a SubNode, or if I should tweak its proxy to display only this SubNode?
    I'm a bit lost as you can see.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.