QTreeView: maintaining mapping between QModelIndex and underlying data
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.
"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
The item will not overwrite itself, but its parent model will.