本文整理汇总了C++中QTimeEdit类的典型用法代码示例。如果您正苦于以下问题:C++ QTimeEdit类的具体用法?C++ QTimeEdit怎么用?C++ QTimeEdit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QTimeEdit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CompareTime
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 );
}
示例2: setModelData
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);
}
}
示例3: QTimeEdit
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;
}
示例4: setEditorData
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 );
}
示例5: Q_UNUSED
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;
}
示例6: switch
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;
}
}
示例7: QGroupBox
//! [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);
}
示例8: setEditorData
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);
}
}
示例9: 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);
}
示例10: setModelData
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);
}
示例11: setModelData
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);
}
}
示例12: QDate
// 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);
}
}
示例13: QTimeEdit
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);
}
}
示例14: if
// 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);
}
}
示例15: switch
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?
}