void CTariffSetting::CompareTime( QTimeEdit &edtTime, QTime &time, bool bSequence ) { if ( !edtTime.isVisible( ) ) { return; } bool bDisplay = bSequence ? ( time > edtTime.time( ) ) : ( time < edtTime.time( ) ); QString strStyle = bDisplay ? "background-color: rgb(255, 0, 0);" : "background-color: rgb(255, 255, 255);"; if ( bDisplay ) { edtTime.setFocus( ); QString strInfo = QString( "%1时间不能%2于%3时间" ).arg( bSequence ? "截止" : "起始", bSequence ? "小" : "大", bSequence ? "起始" : "截止" ); CCommonFunction::MsgBox( NULL, CCommonFunction::GetMsgTitle( QMessageBox::Information ), strInfo, QMessageBox::Information ); } QString strWhite = "background-color: rgb(255, 255, 255);"; ui->tdtSection1->setStyleSheet( strWhite ); ui->tdtSection2->setStyleSheet( strWhite ); edtTime.setStyleSheet( strStyle ); }
void TrackDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { if ( !index.isValid()) { return; } QTimeEdit* timeEditor = qobject_cast<QTimeEdit*>(editor); if ( !timeEditor) { return; } if (isRightColumn(index, TrackDelegate::columnNumber)) { QTime time = timeEditor->time(); int secs = time.hour() * 60 + time.minute(); //int secs = index.model()->data(index, Qt::EditRole).toInt(); model->setData(index, secs, Qt::EditRole); } else { QStyledItemDelegate::setModelData(editor, model, index); } }
void MetaQueryWidget::makeLengthSelection() { QTimeEdit* timeSpin = new QTimeEdit(); timeSpin->setDisplayFormat( "m:ss" ); timeSpin->setMinimumTime( QTime( 0, 0, 0 ) ); timeSpin->setMaximumTime( QTime( 0, 60, 59) ); timeSpin->setTime( QTime().addSecs( m_filter.numValue ) ); connect( timeSpin, SIGNAL(timeChanged(const QTime&)), SLOT(numValueChanged(const QTime&)) ); m_valueSelection1 = timeSpin; if( m_filter.condition != Between ) return; QTimeEdit* timeSpin2 = new QTimeEdit(); timeSpin2->setDisplayFormat( "m:ss" ); timeSpin2->setMinimumTime( QTime( 0, 0, 0 ) ); timeSpin2->setMaximumTime( QTime( 0, 60, 59) ); timeSpin2->setTime( QTime().addSecs( m_filter.numValue2 ) ); connect( timeSpin2, SIGNAL(timeChanged(const QTime&)), SLOT(numValueChanged(const QTime&)) ); m_valueSelection2 = timeSpin2; }
void TimeDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QTime value = index.model()->data(index, Qt::EditRole).toTime(); QTimeEdit *e = static_cast<QTimeEdit*>(editor); e->setMinimumTime( index.model()->data( index, Role::Minimum ).toTime() ); e->setMaximumTime( index.model()->data( index, Role::Maximum ).toTime() ); e->setTime( value ); }
QWidget* TimeProp::createEditor(QWidget * parent, const QModelIndex & index) { Q_UNUSED(index); QTimeEdit *te = new QTimeEdit(parent); te->setTime(value().toTime()); connect(te, SIGNAL(timeChanged(const QTime&)), this, SLOT(setValue(const QTime&))); return te; }
void PupilContActivityDelegate::setModelData ( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const { switch ( index.column() ) { case 2: { QComboBox *combo = qobject_cast<QComboBox *> ( editor ); if ( !combo ) { QItemDelegate::setModelData ( editor, model, index ); return; } model -> setData ( index, combo -> currentIndex() ); } break; case 3: { QComboBox *combo = qobject_cast<QComboBox *> ( editor ); if ( !combo ) { QItemDelegate::setModelData ( editor, model, index ); return; } model -> setData ( index, combo -> currentIndex() ); } break; case 4: { QTimeEdit *time = qobject_cast<QTimeEdit *> ( editor ); if ( !time ) { QItemDelegate::setModelData ( editor, model, index ); } model -> setData ( index, time->time().toString("hh:mm") ); } break; case 5: { QDateEdit *cal = qobject_cast<QDateEdit *> ( editor ); if ( !cal ) { QItemDelegate::setModelData ( editor, model, index ); return; } model -> setData ( index, cal->date().toString("yyyy-MM-dd") ); } break; case 6: { QDateEdit *cal1 = qobject_cast<QDateEdit *> ( editor ); if ( !cal1 ) { QItemDelegate::setModelData ( editor, model, index ); return; } model -> setData ( index, cal1->date().toString("yyyy-MM-dd") ); } break; default: { QItemDelegate::setModelData ( editor, model, index ); return; } break; } }
//! [6] void Window::createDateTimeEdits() { editsGroup = new QGroupBox(tr("Date and time spin boxes")); QLabel *dateLabel = new QLabel; QDateEdit *dateEdit = new QDateEdit(QDate::currentDate()); dateEdit->setDateRange(QDate(2005, 1, 1), QDate(2010, 12, 31)); dateLabel->setText(tr("Appointment date (between %0 and %1):") .arg(dateEdit->minimumDate().toString(Qt::ISODate)) .arg(dateEdit->maximumDate().toString(Qt::ISODate))); //! [6] //! [7] QLabel *timeLabel = new QLabel; QTimeEdit *timeEdit = new QTimeEdit(QTime::currentTime()); timeEdit->setTimeRange(QTime(9, 0, 0, 0), QTime(16, 30, 0, 0)); timeLabel->setText(tr("Appointment time (between %0 and %1):") .arg(timeEdit->minimumTime().toString(Qt::ISODate)) .arg(timeEdit->maximumTime().toString(Qt::ISODate))); //! [7] //! [8] meetingLabel = new QLabel; meetingEdit = new QDateTimeEdit(QDateTime::currentDateTime()); //! [8] //! [9] QLabel *formatLabel = new QLabel(tr("Format string for the meeting date " "and time:")); QComboBox *formatComboBox = new QComboBox; formatComboBox->addItem("yyyy-MM-dd hh:mm:ss (zzz 'ms')"); formatComboBox->addItem("hh:mm:ss MM/dd/yyyy"); formatComboBox->addItem("hh:mm:ss dd/MM/yyyy"); formatComboBox->addItem("hh:mm:ss"); formatComboBox->addItem("hh:mm ap"); //! [9] //! [10] connect(formatComboBox, SIGNAL(activated(const QString &)), this, SLOT(setFormatString(const QString &))); //! [10] setFormatString(formatComboBox->currentText()); //! [11] QVBoxLayout *editsLayout = new QVBoxLayout; editsLayout->addWidget(dateLabel); editsLayout->addWidget(dateEdit); editsLayout->addWidget(timeLabel); editsLayout->addWidget(timeEdit); editsLayout->addWidget(meetingLabel); editsLayout->addWidget(meetingEdit); editsLayout->addWidget(formatLabel); editsLayout->addWidget(formatComboBox); editsGroup->setLayout(editsLayout); }
void TrackDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { if (index.column() == durationColumn) { int secs = index.model()->data(index, Qt::DisplayRole).toInt(); QTimeEdit *timeEdit = qobject_cast<QTimeEdit *>(editor); timeEdit->setTime(QTime(0, secs / 60, secs % 60)); } else { QItemDelegate::setEditorData(editor, index); } }
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); }
void MultiDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { QVariant value; QString className = editor->metaObject()->className(); if (className == "QTimeEdit") { QTimeEdit* ed = qobject_cast<QTimeEdit*>(editor); Q_ASSERT( ed); value = QVariant( ed->time()); } else if (className == "QDateEdit") { QDateEdit* ed = qobject_cast<QDateEdit*>(editor); Q_ASSERT( ed); value = QVariant( ed->date()); } else if (className == "QDateTimeEdit") { QDateTimeEdit* ed = qobject_cast<QDateTimeEdit*>(editor); Q_ASSERT( ed); value = QVariant( ed->dateTime()); } else if (className == "IconViewer") { return; } else if (className == "QComboBox") { QComboBox* ed = qobject_cast<QComboBox*>(editor); Q_ASSERT( ed); value = QVariant( ed->currentText()); } else if (className == "QListWidget") { QListWidget* ed = qobject_cast<QListWidget*>(editor); Q_ASSERT( ed); QStringList valList; int itemCount = ed->count(); for (int i = 0; i < itemCount; ++i) { QListWidgetItem* bitItem = ed->item(i); bool isChecked = (bitItem->checkState() == Qt::Checked); if (isChecked) valList += bitItem->text(); } value = QVariant( valList); } else if (className == "QCheckBox") { QCheckBox* ed = qobject_cast<QCheckBox*>(editor); Q_ASSERT( ed); value = QVariant( ed->isChecked()); } else { QItemDelegate::setModelData( editor, model, index); return; } model->setData(index, value, Qt::EditRole); }
void TrackDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { if (index.column() == durationColumn) { QTimeEdit *timeEdit = qobject_cast<QTimeEdit *>(editor); QTime time = timeEdit->time(); int secs = (time.minute() * 60) + time.second(); model->setData(index, secs); } else { QItemDelegate::setModelData(editor, model, index); } }
// We don't set anything because the data is saved within the view not the model! void RideDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { // stored as text field if (index.column() == dateColumn) { QDateEdit *dateEdit = qobject_cast<QDateEdit *>(editor); QDate date = QDate().fromString(index.model()->data(index, Qt::DisplayRole).toString(), "dd MMM yyyy");; dateEdit->setDate(date); } else if (index.column() == dateColumn+1) { QTimeEdit *timeEdit = qobject_cast<QTimeEdit *>(editor); QTime time = QTime().fromString(index.model()->data(index, Qt::DisplayRole).toString(), "hh:mm:ss a");; timeEdit->setTime(time); } }
QWidget *TrackDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (index.column() == durationColumn) { QTimeEdit *timeEdit = new QTimeEdit(parent); timeEdit->setDisplayFormat("mm:ss"); connect(timeEdit, SIGNAL(editingFinished()), this, SLOT(commitAndCloseEditor())); return timeEdit; } else { return QItemDelegate::createEditor(parent, option, index); } }
// We don't set anything because the data is saved within the view not the model! void RideDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { // stored as text field if (index.column() == dateColumn) { QDateEdit *dateEdit = qobject_cast<QDateEdit *>(editor); QString value = dateEdit->date().toString("dd MMM yyyy"); // Place in the view model->setData(index, value, Qt::DisplayRole); } else if (index.column() == dateColumn+1) { QTimeEdit *timeEdit = qobject_cast<QTimeEdit *>(editor); QString value = timeEdit->time().toString("hh:mm:ss a"); model->setData(index, value, Qt::DisplayRole); } }
QWidget *SelectorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex & index ) const { switch ( index.model()->data( index, Role::EditorType ).toInt() ) { case Delegate::EnumEditor: { QComboBox *editor = new KComboBox(parent); editor->installEventFilter(const_cast<SelectorDelegate*>(this)); return editor; } case Delegate::TimeEditor: { QTimeEdit *editor = new QTimeEdit(parent); editor->installEventFilter(const_cast<SelectorDelegate*>(this)); return editor; } } return 0; // FIXME: What to do? }
QVariant UIPropertyGetters::IntFromTimeGetter(QWidget* editor, SettingsPropertyMapper::WidgetType editorType, SettingsPropertyMapper::PropertyType) { if (editorType == SettingsPropertyMapper::TIME_EDIT) { QTimeEdit* pTimeEdit = qobject_cast<QTimeEdit*>(editor); if (pTimeEdit == NULL) { qCritical() << "IntFromTimeGetter support only QTimeEdit. Unable to cast to QTimeEdit."; return QVariant(); } return StaticHelpers::QTimeToSecs(pTimeEdit->time()); } qCritical() << "IntFromTimeGetter support only QTimeEdit"; return QVariant(); }
void MainWindow::on_subTimeStopCmd_clicked() { qDebug("stop"); int n = widget.tableWidget->currentRow(); if (n < 0) { return; } int t = mpw->getTime(); int ms = t % 1000; t = t / 1000; int h = t / 3600; int m = (t / 60) % 60; int s = t % 60; QTimeEdit *q = qobject_cast<QTimeEdit *>(widget.tableWidget->cellWidget(n, 1)); q->setTime(QTime(h, m, s, ms)); }
void SelectorDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { switch ( index.model()->data( index, Role::EditorType ).toInt() ) { case Delegate::EnumEditor: { QComboBox *box = static_cast<QComboBox*>(editor); int value = box->currentIndex(); model->setData( index, value, Qt::EditRole ); return; } case Delegate::TimeEditor: { QTimeEdit *e = static_cast<QTimeEdit*>(editor); model->setData( index, e->time(), Qt::EditRole ); return; } } }
void UIPropertySetters::TimeFromIntSetter(QWidget* editor, SettingsPropertyMapper::WidgetType editorType, SettingsPropertyMapper::PropertyType propertyType, QVariant propertyValue) { if (editorType == SettingsPropertyMapper::TIME_EDIT) { QTimeEdit* pTimeEdit = qobject_cast<QTimeEdit*>(editor); if (pTimeEdit == NULL) { qCritical() << "TimeFromIntSetter support only QTimeEdit. Unable to cast to QTimeEdit."; return; } int val = propertyValue.toInt(); pTimeEdit->setTime(StaticHelpers::SecsToQTime(val)); } else { qCritical() << "SpinboxKBSetter support only QSpinBox"; } }
// ============================================================================= void TableViewDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { // Day belongs to header int column = index.column(); if (column == Col::START_TIME || column == Col::END_TIME || column == Col::PAUSE_TIME || column == Col::REQUIRED_TIME) { QTimeEdit *timeEdit = qobject_cast<QTimeEdit *>(editor); QTime time = timeEdit->time(); model->setData(index, time); } else { QItemDelegate::setModelData(editor, model, index); } }
// setup editor for edit of field!! QWidget *RideDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (index.column() == dateColumn) { // edit that date! QDateEdit *dateEdit = new QDateEdit(parent); dateEdit->setDisplayFormat("dd MMM yyyy"); connect(dateEdit, SIGNAL(editingFinished()), this, SLOT(commitAndCloseDateEditor())); return dateEdit; } else if (index.column() == dateColumn+1) { // edit that time QTimeEdit *timeEdit = new QTimeEdit(parent); timeEdit->setDisplayFormat("hh:mm:ss a"); connect(timeEdit, SIGNAL(editingFinished()), this, SLOT(commitAndCloseTimeEditor())); return timeEdit; } else { return QItemDelegate::createEditor(parent, option, index); } }
// ============================================================================= void TableViewDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { // Day belongs to header int column = index.column(); if (column == Col::START_TIME || column == Col::END_TIME || column == Col::PAUSE_TIME || column == Col::REQUIRED_TIME) { QTime time = index.model()->data(index, Qt::DisplayRole).toTime(); QTimeEdit *timeEdit = qobject_cast<QTimeEdit *>(editor); timeEdit->setTime(time); } else { QItemDelegate::setEditorData(editor, index); } }
void SelectorDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { switch ( index.model()->data( index, Role::EditorType ).toInt() ) { case Delegate::EnumEditor: { QStringList lst = index.model()->data( index, Role::EnumList ).toStringList(); int value = index.model()->data(index, Role::EnumListValue).toInt(); QComboBox *box = static_cast<QComboBox*>(editor); box->addItems( lst ); box->setCurrentIndex( value ); return; } case Delegate::TimeEditor: QTime value = index.model()->data(index, Qt::EditRole).toTime(); QTimeEdit *e = static_cast<QTimeEdit*>(editor); e->setMinimumTime( index.model()->data( index, Role::Minimum ).toTime() ); e->setMaximumTime( index.model()->data( index, Role::Maximum ).toTime() ); e->setTime( value ); return; } }
void TrackDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { if ( !index.isValid()) { return; } QTimeEdit* timeEditor = qobject_cast<QTimeEdit*>(editor); if ( !timeEditor) { return; } if (isRightColumn(index, TrackDelegate::columnNumber)) { int secs = index.model()->data(index, Qt::EditRole).toInt(); QTime time(secs / 60, secs % 60); timeEditor->setTime(time); } else { QStyledItemDelegate::setEditorData(editor, index); } }
void MainWindow::addRow(bool isUp) { int n = widget.tableWidget->currentRow(); // qDebug(QString::number(n).toStdString().c_str()); if (isUp) { // n; } else { n++; } if (n < 0) { n = 0; } widget.tableWidget->insertRow(n); QTimeEdit *st = new QTimeEdit(widget.tableWidget); st->setDisplayFormat("HH:mm:ss.zzz"); QTimeEdit *ft = new QTimeEdit(widget.tableWidget); ft->setDisplayFormat("HH:mm:ss.zzz"); QTextEdit *edit = new QTextEdit(widget.tableWidget); QSpinBox *spin = new QSpinBox(widget.tableWidget); spin->setRange(0, 100000); QObject::connect(st, SIGNAL(timeChanged(QTime)), this, SLOT(timesChanged(QTime))); QObject::connect(ft, SIGNAL(timeChanged(QTime)), this, SLOT(timesChanged(QTime))); // widget.tableWidget->model() widget.tableWidget->setCellWidget(n, 0, st); widget.tableWidget->setCellWidget(n, 1, ft); widget.tableWidget->setCellWidget(n, 2, spin); widget.tableWidget->setCellWidget(n, 3, edit); // widget.tableWidget->row(st); }
void MainWindow::on_subTimeStartCmd_clicked() { qDebug("start"); int n = widget.tableWidget->currentRow(); if (n < 0) { return; } // widget.textEdit->setText(QString::number(mpw->getTime())); int t = mpw->getTime(); int ms = t % 1000; t = t / 1000; int h = t / 3600; int m = (t / 60) % 60; int s = t % 60; cout<<t<<" "<<n<<endl; QTimeEdit *q = qobject_cast<QTimeEdit *>(widget.tableWidget->cellWidget(n, 0)); QTimeEdit *q2 = qobject_cast<QTimeEdit *>(widget.tableWidget->cellWidget(n, 1)); q->setTime(QTime(h, m, s, ms)); // q2->setTime(QTime(h, m, s, ms)); }
// ============================================================================= QWidget *TableViewDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { // Day belongs to header int column = index.column(); if (column == Col::START_TIME || column == Col::END_TIME || column == Col::PAUSE_TIME || column == Col::REQUIRED_TIME) { QTimeEdit *timeEdit = new QTimeEdit(parent); timeEdit->setDisplayFormat("hh:mm"); connect(timeEdit, SIGNAL(editingFinished()), this, SLOT(commitAndCloseTimeEdit())); return timeEdit; } else { return QItemDelegate::createEditor(parent, option, index); } }
QWidget* TrackDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (isRightColumn(index, TrackDelegate::columnNumber)) { QTimeEdit *timeEdit = new QTimeEdit(parent); timeEdit->setDisplayFormat("hh:mm"); connect(timeEdit, &QTimeEdit::editingFinished, this, &TrackDelegate::commitAndCloseEditor); //int secs = index.model()->data(index, Qt::DisplayRole).toInt(); int secs = index.model()->data(index, Qt::EditRole).toInt(); QTime time(secs / 60, secs % 60); timeEdit->setTime(time); return timeEdit; } else { return QStyledItemDelegate::createEditor(parent, option, index); } }
QTime QtopiaInputDialog::getTime(QWidget *parent, const QString &title, const QString &label, const QTime &time, const QTime &minTime, const QTime &maxTime, bool *ok) { QTimeEdit *te = new QTimeEdit(time); QFont font(te->font()); font.setPointSize(font.pointSize()+3); te->setFont(font); te->setMinimumTime(minTime); te->setMaximumTime(maxTime); QtopiaInputDialog dlg(parent, title, label, te); bool accepted = (QtopiaApplication::execDialog(&dlg) == QDialog::Accepted); if (ok) *ok = accepted; return te->time(); }
void MainWindow::timesChanged(QTime t) { //when time edit event occur return; QWidget *wid = QApplication::focusWidget(); QTimeEdit *cell = qobject_cast<QTimeEdit*>(wid); QTimeEdit *st; QTimeEdit *et; QSpinBox *du; int start, end; if (wid) { QModelIndex index = widget.tableWidget->indexAt(cell->pos()); // cout << index.row() << " " << index.column() << endl; if (index.column() == 0) { st = cell; et = qobject_cast<QTimeEdit*>(widget.tableWidget->cellWidget(index.row(), 1)); } else { et = cell; st = qobject_cast<QTimeEdit*>(widget.tableWidget->cellWidget(index.row(), 0)); } QTime tt; tt = st->time(); start = tt.msec() + 1000 * (tt.second() + tt.minute()*60 + tt.hour()*3600); tt = et->time(); end = tt.msec() + 1000 * (tt.second() + tt.minute()*60 + tt.hour()*3600); if (start > end) { if (index.column() == 0) { // st->setTime(et->time()); } else { // et->setTime(st->time()); } } du = qobject_cast<QSpinBox*>(widget.tableWidget->cellWidget(index.row(), 2)); du->setValue(end - start); delete wid; delete cell; delete et; delete st; delete du; } }