Does each item in a QStandardItemModel have a unique QModelIndex?

47 views Asked by At

I have a QStandardItem Model with QStandardItems that look like this

  • USA
    • Population
    • Capital city
  • France
    • Population
    • Capital city

When a user doubleClicked signal is sent by the user, I can get a QModelIndex with a data() method so that if they double-click on, say, "Population", then data() will return "Population".

My question. Does the QModelIndex distinguish between, say, the QStandardItems belonging to USA from those belonging to france? Is there a more elegant solution than stuff like model_index.parent().parent()... ? An ideal solution would be a function like

def get_standard_item(model: QStandardItemModel, index: QModelIndex) -> QStandardItem:
...

[edit] - I found this in the QModelIndex class documentation:

"QModelIndex::internalId() - Returns a quintptr used by the model to associate the index with the internal data structure."

Can this be used somehow to fetch the corresponding QStandardItem?

0

There are 0 answers