Exemplo n.º 1
0
QDate FatCRMInputDialog::getDate(const QString &caption, const QString &labelText, const QDate &value, bool *ok)
{
    QDialog dialog;
    dialog.setWindowTitle(caption);

    QVBoxLayout *layout = new QVBoxLayout(&dialog);

    QLabel *label = new QLabel(&dialog);
    label->setText(labelText);

    QDateEditEx *dateEdit = new QDateEditEx(&dialog);
    dateEdit->setCalendarPopup(true);
    dateEdit->setDate(value);

    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);

    layout->addWidget(label);
    layout->addWidget(dateEdit);
    layout->addStretch();
    layout->addWidget(buttonBox);

    QObject::connect(buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept()));
    QObject::connect(buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject()));

    const bool result = (dialog.exec() == QDialog::Accepted);

    if (ok) {
        *ok = result;
    }

    if (result)
        return dateEdit->date();

    return QDate();
}
Exemplo n.º 2
0
DateEditTest::DateEditTest(QWidget *parent) :
    QMainWindow(parent)
{
    QWidget *wid = new QWidget;
    QVBoxLayout *layout = new QVBoxLayout(wid);
    QDateEditEx *edit = new QDateEditEx(wid);
    edit->setCalendarPopup(true);
    edit->setNullable(true);
    layout->addWidget(edit);
    edit = new QDateEditEx(wid);
    edit->setCalendarPopup(true);
    layout->addWidget(edit);
    QLineEdit *ledit = new QLineEdit(wid);
    layout->addWidget(ledit);

    wid->setLayout(layout);


    setCentralWidget(wid);
}