Thanks for pointing me in the right direction. For anyone who is interested, this is my final solution to the problem:
model->setTable("mytable");
model->select();
mapper->setModel(model);
mapper->setItemDelegate(new NullDelegate);
mapper->addMapping(ui->empRefEdit, 1);
model = new QSqlRelationalTableModel(this);
model->setTable("mytable");
model->select();
mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
mapper->setItemDelegate(new NullDelegate);
mapper->addMapping(ui->empRefEdit, 1);
To copy to clipboard, switch view to plain text mode
And the delegate:
{
Q_OBJECT
public:
NullDelegate
(QObject *parent
= 0);
};
{
model->setData(index, editor->property("text") == "" ?
editor->property("text"));
}
{
editor->setProperty("text", index.data());
}
class NullDelegate : public QItemDelegate
{
Q_OBJECT
public:
NullDelegate (QObject *parent = 0);
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
};
void NullDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
model->setData(index, editor->property("text") == "" ?
QVariant() :
editor->property("text"));
}
void NullDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
editor->setProperty("text", index.data());
}
To copy to clipboard, switch view to plain text mode
Now, the next problem..... what if I need to use a QSqlRelationalDelegate as well to populate some combo boxes?
Bookmarks