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. QTreeView: maintaining mapping between QModelIndex and underlying data

QTreeView: maintaining mapping between QModelIndex and underlying data

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.1k Views
  • 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.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

    I have problems migrating from QTreeWidget to QtreeView. Things that were obvious and trivial with QTreeWidget seem to be impossible with view. Specifically: I have a main window with a tree view in it. TreeView uses the model I've implemented, but not directly - through QSortFilterProxyModel that is set as a tree's model. Now, the user activates an item in the tree and main windows receives a signal itemActivated(QModelIndex item). How can I tell which item of the underlying data was activated? Data is a vector, so with TreeWidget I could just store an item's vector index in the QTreeWidgetItem, but QModelIndex doesn't even have setData API.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thEClaw
      wrote on last edited by
      #2

      "mapToSource()":http://qt-project.org/doc/qt-5.1/qtcore/qabstractproxymodel.html#mapToSource should be what you are looking for.

      If you want to "write to a model index", use the somewhat more complicated combination of
      "setData()":http://qt-project.org/doc/qt-5.1/qtcore/qabstractitemmodel.html#setData
      "index()":http://qt-project.org/doc/qt-5.1/qtcore/qabstractitemmodel.html#index

      The item will not overwrite itself, but its parent model will.

      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