本文整理汇总了C++中QDateTimeEdit类的典型用法代码示例。如果您正苦于以下问题:C++ QDateTimeEdit类的具体用法?C++ QDateTimeEdit怎么用?C++ QDateTimeEdit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QDateTimeEdit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setEditorData
void DateTimeCalendarDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
QDateTime value = index.model()->data(index, Qt::EditRole).toDateTime();
QDateTimeEdit *e = static_cast<QDateTimeEdit*>(editor);
e->setDateTime( value );
}
示例2: defaultValue
QWidget * ExtArgTimestamp::createEditor(QWidget * parent)
{
QDateTimeEdit * tsBox;
QString text = defaultValue();
if ( _argument->pref_valptr && *_argument->pref_valptr)
{
QString storeValue(*_argument->pref_valptr);
if ( storeValue.length() > 0 && storeValue.compare(text) != 0 )
text = storeValue.trimmed();
}
ts = QDateTime::fromTime_t(text.toInt());
tsBox = new QDateTimeEdit(ts, parent);
tsBox->setDisplayFormat(QLocale::system().dateTimeFormat());
tsBox->setCalendarPopup(true);
if ( _argument->tooltip != NULL )
tsBox->setToolTip(QString().fromUtf8(_argument->tooltip));
connect(tsBox, SIGNAL(dateTimeChanged(QDateTime)), SLOT(onDateTimeChanged(QDateTime)));
return tsBox;
}
示例3: setEditorData
void QFRDRTableDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
QDateTimeEdit *dateEditor = qobject_cast<QDateTimeEdit *>(editor);
if (dateEditor) {
dateEditor->setDateTime(index.model()->data(index, Qt::EditRole).toDateTime());
} else {
QFDoubleEdit *dEditor = qobject_cast<QFDoubleEdit *>(editor);
if (dEditor) {
dEditor->setValue(index.model()->data(index, Qt::EditRole).toDouble());
} else {
QSpinBox *sEditor = qobject_cast<QSpinBox *>(editor);
if (sEditor) {
sEditor->setValue(index.model()->data(index, Qt::EditRole).toLongLong());
} else {
QCheckBox *check = qobject_cast<QCheckBox *>(editor);
if (check) {
check->setChecked(index.model()->data(index, Qt::EditRole).toBool());
} else {
QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
if (edit) {
edit->setText(index.model()->data(index, Qt::EditRole).toString());
}
}
}
}
}
}
示例4: v
void QFRDRTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
QFDoubleEdit *dEditor = qobject_cast<QFDoubleEdit *>(editor);
if (dEditor) {
QVariant v( dEditor->value());
v.convert(QVariant::Double);
//qDebug()<<v;
model->setData(index, v);
} else {
QDateTimeEdit *dateEditor = qobject_cast<QDateTimeEdit *>(editor);
if (dateEditor) {
model->setData(index, dateEditor->dateTime());
} else {
QSpinBox *sEditor = qobject_cast<QSpinBox *>(editor);
if (sEditor) {
model->setData(index, sEditor->value());
} else {
QCheckBox *check = qobject_cast<QCheckBox *>(editor);
if (check) {
model->setData(index, check->isChecked());
} else {
QLineEdit *edit = qobject_cast<QLineEdit*>(editor);
if (edit) {
model->setData(index, edit->text());
}
}
}
}
}
}
示例5: QDateTimeEdit
QWidget *DateTimeCalendarDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const
{
QDateTimeEdit *editor = new QDateTimeEdit(parent);
editor->setCalendarPopup( true );
editor->installEventFilter(const_cast<DateTimeCalendarDelegate*>(this));
return editor;
}
示例6: QDateTimeEdit
QWidget *SpreadSheetDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &,
const QModelIndex &index) const
{
if (index.column() == 1) {
QDateTimeEdit *editor = new QDateTimeEdit(parent);
editor->setDisplayFormat("dd/M/yyyy");
editor->setCalendarPopup(true);
return editor;
}
QLineEdit *editor = new QLineEdit(parent);
// create a completer with the strings in the column as model
QStringList allStrings;
for (int i = 1; i<index.model()->rowCount(); i++) {
QString strItem(index.model()->data(index.sibling(i, index.column()),
Qt::EditRole).toString());
if (!allStrings.contains(strItem))
allStrings.append(strItem);
}
QCompleter *autoComplete = new QCompleter(allStrings);
editor->setCompleter(autoComplete);
connect(editor, &QLineEdit::editingFinished, this, &SpreadSheetDelegate::commitAndCloseEditor);
return editor;
}
示例7: QVBoxLayout
void PosService::on_btSetTime_clicked()
{
int button_width = data->getVariables()->value(_S("standart_button_width")).toInt();
int button_height = data->getVariables()->value(_S("standart_button_height")).toInt();
int button_margin = data->getVariables()->value(_S("standart_margins")).toInt();
QDialog dlg;
QVBoxLayout* mainLayout = new QVBoxLayout();
dlg.setLayout(mainLayout);
dlg.setWindowTitle(_T("Установка времени"));
QDateTimeEdit* edit = new QDateTimeEdit(QDateTime::currentDateTime());
edit->setMaximumHeight(button_height);
edit->setMinimumHeight(button_height);
mainLayout->addWidget(edit);
QHBoxLayout *btLayout = new QHBoxLayout();
mainLayout->addLayout(btLayout);
QPushButton* bt;
bt = new QPushButton(_T("OK"), this);
bt->setMaximumSize(button_width * 2 + button_margin, button_height);
bt->setMinimumSize(button_width * 2 + button_margin, button_height);
btLayout->addWidget(bt);
connect(bt, SIGNAL(clicked()), &dlg, SLOT(accept()));
bt = new QPushButton(_T("Отмена"), this);
bt->setMaximumSize(button_width * 2 + button_margin, button_height);
bt->setMinimumSize(button_width * 2 + button_margin, button_height);
btLayout->addWidget(bt);
connect(bt, SIGNAL(clicked()), &dlg, SLOT(reject()));
int result = dlg.exec();
if(result==QDialog::Accepted)
{
QString dt = edit->dateTime().toString(data->getSettings()->value("posservice/command_setdatetime_format").toString());
QString command = data->getSettings()->value("posservice/command_setdatetime").toString().arg(dt);
if (loglevel > 0)
qDebug() << _T("%1 Устанавливаем новое время: %2 (было: %3)")
.arg(posForLog)
.arg(edit->dateTime().toString(Qt::ISODate))
.arg(QDateTime::currentDateTime().toString(Qt::ISODate));
int result = QProcess::execute(command);
if(result<0)
{
qDebug() << _T("%1 Ошибка установки нового времени. Код ошибки: %2")
.arg(posForLog)
.arg(result);
QMessageBox message;
message.setText(_T("Ошибка установки нового времени.\nКод ошибки: %1").arg(result));
message.exec();
}
}
}
示例8: readAnniversary
void ContactDialog::readAnniversary(int num, DateItem &ann)
{
QDateTimeEdit* editor = findChild<QDateTimeEdit*>
(QString("dteAnn%1Date").arg(num));
if (!editor) return;
anniversaryDetails[num-1].value = editor->dateTime();
ann = anniversaryDetails[num-1];
}
示例9: setEditorData
void MyDateItemDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
const QDateTime& value = index.model()->data(index, Qt::DisplayRole).toDateTime();
QDateTimeEdit *e = static_cast<QDateTimeEdit*>(editor);
e->setDateTime(value);
}
示例10: addTimePropertyRow
void DocumentPropertiesWidget::addTimePropertyRow(
const char *rowTitle, const QString &propertyName)
{
QDateTimeEdit *propertyValue = new QDateTimeEdit;
propertyValue->setReadOnly(true);
addRowWithTitleAndValue(rowTitle, propertyValue);
new MetaDataBinding(propertyValue, "dateTime", resultSet, propertyName, this);
}
示例11: QLabel
//! [0]
MainWindow::MainWindow()
{
selectedDate = QDate::currentDate();
fontSize = 10;
QWidget *centralWidget = new QWidget;
//! [0]
//! [1]
QLabel *dateLabel = new QLabel(tr("Date:"));
QComboBox *monthCombo = new QComboBox;
for (int month = 1; month <= 12; ++month)
monthCombo->addItem(QDate::longMonthName(month));
QDateTimeEdit *yearEdit = new QDateTimeEdit;
yearEdit->setDisplayFormat("yyyy");
yearEdit->setDateRange(QDate(1753, 1, 1), QDate(8000, 1, 1));
//! [1]
monthCombo->setCurrentIndex(selectedDate.month() - 1);
yearEdit->setDate(selectedDate);
//! [2]
QLabel *fontSizeLabel = new QLabel(tr("Font size:"));
QSpinBox *fontSizeSpinBox = new QSpinBox;
fontSizeSpinBox->setRange(1, 64);
fontSizeSpinBox->setValue(10);
editor = new QTextBrowser;
insertCalendar();
//! [2]
//! [3]
connect(monthCombo, SIGNAL(activated(int)), this, SLOT(setMonth(int)));
connect(yearEdit, SIGNAL(dateChanged(QDate)), this, SLOT(setYear(QDate)));
connect(fontSizeSpinBox, SIGNAL(valueChanged(int)),
this, SLOT(setFontSize(int)));
//! [3]
//! [4]
QHBoxLayout *controlsLayout = new QHBoxLayout;
controlsLayout->addWidget(dateLabel);
controlsLayout->addWidget(monthCombo);
controlsLayout->addWidget(yearEdit);
controlsLayout->addSpacing(24);
controlsLayout->addWidget(fontSizeLabel);
controlsLayout->addWidget(fontSizeSpinBox);
controlsLayout->addStretch(1);
QVBoxLayout *centralLayout = new QVBoxLayout;
centralLayout->addLayout(controlsLayout);
centralLayout->addWidget(editor, 1);
centralWidget->setLayout(centralLayout);
setCentralWidget(centralWidget);
//! [4]
}
示例12: setEditorData
void setEditorData(QWidget *editor, const QModelIndex &index) const {
QDateTimeEdit *edit = qobject_cast<QDateTimeEdit *>(editor);
if (!edit) {
QItemDelegate::setEditorData(editor, index);
return;
}
QString time = index.model()->data(index,Qt::EditRole).toString();
edit->setDateTime(QDateTime::fromString(time, "yyyy-MM-dd hh:mm"));
}
示例13: setModelData
void MyDateItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
QDateTimeEdit *e = static_cast<QDateTimeEdit*>(editor);
e->interpretText();
const QDateTime& value = e->dateTime();
model->setData(index, value.toString(DATETIMEFORMAT), Qt::EditRole);
}
示例14: QDateTimeEdit
QWidget *MyDateItemDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex & index ) const
{
QDateTimeEdit *editor = new QDateTimeEdit(parent);
editor->setCalendarPopup(true);
editor->setDisplayFormat(DATETIMEFORMAT);
editor->setDateTime(QDateTime::fromString(index.data().toString(), DATETIMEFORMAT));
return editor;
}
示例15: QFETCH
void tst_QItemDelegate::dateTimeEditor()
{
QFETCH(QTime, time);
QFETCH(QDate, date);
QTableWidgetItem *item1 = new QTableWidgetItem;
item1->setData(Qt::DisplayRole, time);
QTableWidgetItem *item2 = new QTableWidgetItem;
item2->setData(Qt::DisplayRole, date);
QTableWidgetItem *item3 = new QTableWidgetItem;
item3->setData(Qt::DisplayRole, QDateTime(date, time));
QTableWidget widget(1, 3);
widget.setItem(0, 0, item1);
widget.setItem(0, 1, item2);
widget.setItem(0, 2, item3);
widget.show();
widget.editItem(item1);
QTestEventLoop::instance().enterLoop(1);
QTimeEdit *timeEditor = qFindChild<QTimeEdit *>(widget.viewport());
QVERIFY(timeEditor);
QCOMPARE(timeEditor->time(), time);
widget.clearFocus();
qApp->setActiveWindow(&widget);
widget.setFocus();
widget.editItem(item2);
QTestEventLoop::instance().enterLoop(1);
QDateEdit *dateEditor = qFindChild<QDateEdit *>(widget.viewport());
QVERIFY(dateEditor);
QCOMPARE(dateEditor->date(), date);
widget.clearFocus();
widget.setFocus();
widget.editItem(item3);
QTestEventLoop::instance().enterLoop(1);
QList<QDateTimeEdit *> dateTimeEditors = widget.findChildren<QDateTimeEdit *>();
QDateTimeEdit *dateTimeEditor = 0;
foreach(dateTimeEditor, dateTimeEditors)
if (dateTimeEditor->metaObject()->className() == QLatin1String("QDateTimeEdit"))
break;
QVERIFY(dateTimeEditor);
QCOMPARE(dateTimeEditor->date(), date);
QCOMPARE(dateTimeEditor->time(), time);
}