
Originally Posted by
wysota
How do your setEditorData() and setModelData() implementations look like?
{
QComboBox *edit
= qobject_cast<QComboBox
*>
(editor
);
QString value
= index.
model()->data
(index, Qt
::EditRole).
toString();
edit->setCurrentIndex(edit->findText(value));
}
void ComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QComboBox *edit = qobject_cast<QComboBox *>(editor);
QString value = index.model()->data(index, Qt::EditRole).toString();
edit->setCurrentIndex(edit->findText(value));
}
To copy to clipboard, switch view to plain text mode
{
QComboBox *edit
= qobject_cast<QComboBox
*>
(editor
);
QString oldVal
= index.
model()->data
(index, Qt
::EditRole).
toString();
QString newVal
= edit
->currentText
();
if (oldVal != newVal)
{
model->setData(index, newVal);
}
// qDebug() << "setModelData: index = " << edit->currentIndex();
}
void ComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QComboBox *edit = qobject_cast<QComboBox *>(editor);
QString oldVal = index.model()->data(index, Qt::EditRole).toString();
QString newVal = edit->currentText();
if (oldVal != newVal)
{
model->setData(index, newVal);
}
// qDebug() << "setModelData: index = " << edit->currentIndex();
}
To copy to clipboard, switch view to plain text mode
I know what you're going to say right here, the answer is in setModelData. sure, yes.
But I don't use QComboBox::currentIndex() here, I need to access it outside these methods to evaluate the selections/entry of both columns before calling a saveRecord() method.
Bookmarks