Qt5 Is it possible to retrieve an item's checkstate from a combobox without having a pointer to the model?

StackOverflow https://stackoverflow.com/questions/19074024

質問

I know you can do it when you have access to the QStandardItemModel but using combobox->model() returns a QAbstractItemModel which doesn't have the item(int row, int col) accessor. I've tried working with QAbstractItemModel::itemData(QModelIndex) but can't get it to work as I require.

I just need to get the CheckState of the items, if(item.checkState() == Qt::Checked) etc...

Edit: I have this code, can I cast it to a QStandardItem?

QModelIndex index(1, 0);
QVariant item = ui->SearchAssessmentCombo->model()->data(index, Qt::CheckStateRole);
役に立ちましたか?

解決

You can't declare an index yourself, all indices are tied to a model. Internally, the data() function will determine that the index you gave in the parameter does not belong to the model and will return null values for everything.

You need to ask your model to give you a valid index before you can use it.

QModelIndex index = ui->SearchAssessmentCombo->model()->index(1,0);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top