Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Sync QTreeView selection with QTableView root
Qt 6.11 is out! See what's new in the release blog

Sync QTreeView selection with QTableView root

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved