Hi, sorry for the late reply to this post but I was struggling with the same problem and think I have worked out the solution.
The problem seems to be that the QDataWidgetMapper doesn't re-populate itself correctly after updates to the model when the submit policy is QDataWidgetMapper::AutoSubmit. This is true of both the standard item delegate and the QSqlRelationalDelegate (which just calls the standard delegate if it is not populating a combo box anyway).
To get a QLineEdit to work well with a QDataWidgetMapper and a QRelationalTableModel it is necessary to subclass either QItemDelegate or QSqlRelationalDelegate as follows:
{
if (!strcmp(editor->metaObject()->className(),"QLineEdit")) {
QLineEdit *le
= qobject_cast<QLineEdit
*>
(editor
);
le->setText(index.data().toString());
}
else
}
void MyItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if (!strcmp(editor->metaObject()->className(),"QLineEdit")) {
QLineEdit *le = qobject_cast<QLineEdit *>(editor);
le->setText(index.data().toString());
}
else
QItemDelegate::setEditorData(editor, index);
}
To copy to clipboard, switch view to plain text mode
Then install MyItemDelegate in the same way as you installed QSqlRelationalDelegate:
mapper->setItemDelegate(new MyItemDelegate);
mapper->setItemDelegate(new MyItemDelegate);
To copy to clipboard, switch view to plain text mode
Hope this helps someone, or if I have got something wrong I would be happy to hear why.
Bookmarks