Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED] Display issue on QTableView
Currently I'm working on specific application, overall subject is not important here. I want to create two views which use the same model. My model should contain information like this:
- node name (QString as QVariant in Qt::DisplayRole),
- map of property name and property value (map as QVariant in Qt::UserRole + 1).
My QTreeView uses only node name (stored in DisplayRole of QStandardItem). Basically I want to select entry on my QTreeView and display every entry of selected element map in QTableView. How can I do this? Should I use somehow two models or stay with one? Maybe should I store my information somewhere else? All my current work is based on QStandardItemModel and QStandardItem. My QTableView have to display only selected item map entries, generally that's where I'm getting confused.
In addition, I would like to have my table cells to be QLineEdits (or some derivative) - I would like to store last text cursor position (in order to paste something on that place). I should use custom delegate, am I correct?
franku last edited by
You probably want to subclass QAbstractItemModel similar to this "Example":http://harmattan-dev.nokia.com/docs/library/html/qt4/itemviews-editabletreemodel.html.
In this case you can use only one model that gives all information to the treeview. You can control the amount of data within each item with the data() and the rowCount() methods. So there is no need to provide a map.
I would suggest reading the descriptions in the example from above step by step and come back with questions.
I guess I understand concepts of subclassing QAbstractItemModel, but I did it other way. I've already prepared QStandardItemModel to store my specific information. My question is how to limit table view scope that it displays only my inner data from selected item in tree view. Any ideas?
franku last edited by
What do you mean with table view scope in respect to inner data? Do you want to select one item in a view, and the selected in a second?
Sorry, maybe I didn't explain it clearly enough. I'd like to have two views (which uses model). First view is tree view. I'd like to display there every item I have added to my model. That items would be identified by QString (QVariant in Qt::DisplayMode). Second view is table view. I'd like to display there every entry in QMap<QString, QString> (QVariant in Qt::UserRole + 1). And the most important thing - I'd like to display in table view properties (I mean QMap<QString, QString> I mentioned before) only from item that is selected in tree view. Literally I want to limit displaying scope of table view only to item that is selected in tree view.
Hope it's clear right now :).
I managed to accomplish what I wanted. I simply create second model connected to table view. Then I connected tree view selection model signal (selectionChanged) to table view connected model custom slot (handleSelectionChange) which populates its model.