Get data from PySide combobox model

I have a data model and a QListView widget. Filling widget with setModel:

self.listProjects.setModel(Model(<data_projects>))

If I need to get data from the selected row

model_index = self.listProjects.currentIndex()
project_id = model_index.data(QtCore.Qt.UserRole + 1)

So far so good, but it does not work with QComboBox

asset_index = self.comboboxAsset.currentIndex()

returns integer instead of QModelIndex… How should I retrieve data from QComboBox?

With a QComboBox you should be able to use currentText to get the string value

Right, but I don`t need string as well, I need to have access to my data (same as with QListView, so I can get anything I need from the database)!

asset_index = self.comboboxAsset.model().index(self.comboboxAsset.currentIndex(), 0)
asset_id = asset_index.data(QtCore.Qt.UserRole + 1)
1 Like