Index of an item in a treeview
-
So this is a python tool.
We have the next scenario
I have defined a custom item class based on QStandardItem and I have a model using QStandardItemModel and populating a treeview.
I populate the treeview based on data from a list which contain objects that have different parameters and so on. Because of the objects and how it's inside I get a nested treeview, but that shouldn't be a problem here.
And I also have a tablemodel based on QAbstractTableModel, and a tabelview.Based on the data from the list I would like to be able to match it against an unique identifier an index to say so, so when I click for example the first item in the treeview, it would populate the table with data that's in that list at index 0, and so on.
Trying to get the row number as index doesn't help that much as each index is only consistent in relation to all siblings at the same level.Now is there any way to for example assign for each standarditem or in the model somehow and index for each row and then use that to get the item in the list?
Thank you!
-
@AndreiDS
I don't follow the details of your particular case. But are you aware that any Qt model'sdata()
/setData()
can be used to store & retrieve any arbitrary value by using a role number you define fromQt::UserRole
upward?So whatever you actual data in a model row/column you can always add a
setData(model->index(row, col), real_data); setData(model->index(row, col), something_like_a_ unique_id, Qt::UserRole);
So when you are putting data into the model you can add whatever you want as a "reference" with it, to be retrieved later via
data(index, Qt::UserRole)
.