QTreeView: maintaining mapping between QModelIndex and underlying data
-
wrote on 22 Sept 2013, 08:06 last edited by
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.
-
wrote on 22 Sept 2013, 13:47 last edited by
"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#indexThe item will not overwrite itself, but its parent model will.
1/2