The following code show you how I'm using the QDateEdit widget:
{
ui.setupUi(this);
this->setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
this->setAttribute(Qt::WA_DeleteOnClose);
modelAME = model;
modelAME->database().transaction();
if (isItNew < 0)
{
id = modelAME->rowCount();
modelAME->insertRow(id);
ui.
dedData->setDate
(QDate::currentDate());
}
else
{
id = isItNew;
}
ui.dedData->setDisplayFormat("dd/MM/yyyy"); //QDateEdit widget
mapper->setModel(modelAME);
//...
//...
mapper->addMapping(ui.dedData, 9); // the QDateEdit widget is mapped to a date field
mapper->setCurrentIndex(id);
connect(ui.btnAnnulla, SIGNAL(clicked()), this, SLOT(revert()));
connect(ui.btnOk, SIGNAL(clicked()), this, SLOT(submit()));
qDebug() << "frmEntUsc_AME Loaded!";
}
frmEntUsc_AME::frmEntUsc_AME(QSqlRelationalTableModel *model,
const int &isItNew, QWidget *parent) : QDialog(parent)
{
ui.setupUi(this);
this->setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
this->setAttribute(Qt::WA_DeleteOnClose);
modelAME = new QSqlTableModel(this);
modelAME = model;
modelAME->database().transaction();
if (isItNew < 0)
{
id = modelAME->rowCount();
modelAME->insertRow(id);
ui.dedData->setDate(QDate::currentDate());
}
else
{
id = isItNew;
}
ui.dedData->setDisplayFormat("dd/MM/yyyy"); //QDateEdit widget
mapper = new QDataWidgetMapper(this);
mapper->setModel(modelAME);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
//...
//...
mapper->addMapping(ui.dedData, 9); // the QDateEdit widget is mapped to a date field
mapper->setCurrentIndex(id);
connect(ui.btnAnnulla, SIGNAL(clicked()), this, SLOT(revert()));
connect(ui.btnOk, SIGNAL(clicked()), this, SLOT(submit()));
qDebug() << "frmEntUsc_AME Loaded!";
}
To copy to clipboard, switch view to plain text mode
Bookmarks