本文整理汇总了C++中QCalendarWidget::setSelectedDate方法的典型用法代码示例。如果您正苦于以下问题:C++ QCalendarWidget::setSelectedDate方法的具体用法?C++ QCalendarWidget::setSelectedDate怎么用?C++ QCalendarWidget::setSelectedDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QCalendarWidget
的用法示例。
在下文中一共展示了QCalendarWidget::setSelectedDate方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: s_searchFecha
void BlDateSearch::s_searchFecha()
{
BL_FUNC_DEBUG
QDialog *diag = new QDialog ( 0 );
diag->setModal ( true );
QCalendarWidget *calend = new QCalendarWidget ( diag );
/// Se pone el 1er dia del calendario a lunes.
calend->setFirstDayOfWeek ( Qt::Monday );
/// Evitar fechas demasiado antiguas
calend->setMinimumDate( QDate ( 1900, 1, 1 ) );
/// Si el campo estaba vacío, seleccionar una fecha imposible, pero mostrar el mes actual
if ( m_textoFecha->text().isEmpty() ) {
calend->setSelectedDate ( calend->minimumDate() );
calend->setCurrentPage ( QDate::currentDate().year(), QDate::currentDate().month() );
}
/// Si ya hay una fecha en el campo, abrir el calendario con ese día seleccionado inicialmente
else {
calend->setSelectedDate ( blNormalizeDate ( m_textoFecha->text() ) );
}
connect ( calend, SIGNAL ( activated ( const QDate & ) ), diag, SLOT ( accept() ) );
/// Creamos un layout donde estara el contenido de la ventana y la ajustamos al QDialog
/// para que sea redimensionable y aparezca el titulo de la ventana.
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget ( calend );
layout->setMargin ( 0 );
layout->setSpacing ( 0 );
diag->setLayout ( layout );
diag->setWindowTitle ( _ ( "Seleccione fecha" ) );
diag->exec();
/// Si la fecha es imposible, significa que el usuario no ha seleccionado una fecha
/// y su campo debe quedarse como estaba: vacío
if ( calend->selectedDate() != QDate ( 1900, 1, 1 ) ) {
m_textoFecha->setText ( calend->selectedDate().toString ( "dd/MM/yyyy" ) );
}
/// Liberamos la memoria
delete layout;
delete calend;
delete diag;
emit ( valueChanged ( m_textoFecha->text() ) );
emit ( editingFinished () );
}
示例2: buttonClickCheck
void tst_QCalendarWidget::buttonClickCheck()
{
QCalendarWidget object;
QSize size = object.sizeHint();
object.setGeometry(0,0,size.width(), size.height());
object.show();
object.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&object));
QDate selectedDate(2005, 1, 1);
//click on the month buttons
int month = object.monthShown();
QToolButton *button = object.findChild<QToolButton *>("qt_calendar_prevmonth");
QTest::mouseClick(button, Qt::LeftButton);
QCOMPARE(month > 1 ? month-1 : 12, object.monthShown());
button = object.findChild<QToolButton *>("qt_calendar_nextmonth");
QTest::mouseClick(button, Qt::LeftButton);
QCOMPARE(month, object.monthShown());
button = object.findChild<QToolButton *>("qt_calendar_yearbutton");
QTest::mouseClick(button, Qt::LeftButton, Qt::NoModifier, button->rect().center(), 2);
QVERIFY(!button->isVisible());
QSpinBox *spinbox = object.findChild<QSpinBox *>("qt_calendar_yearedit");
QTest::qWait(500);
QTest::keyClick(spinbox, '2');
QTest::keyClick(spinbox, '0');
QTest::keyClick(spinbox, '0');
QTest::keyClick(spinbox, '6');
QTest::qWait(500);
QWidget *widget = object.findChild<QWidget *>("qt_calendar_calendarview");
QTest::mouseMove(widget);
QTest::mouseClick(widget, Qt::LeftButton);
QCOMPARE(2006, object.yearShown());
object.setSelectedDate(selectedDate);
object.showSelectedDate();
QTest::keyClick(widget, Qt::Key_Down);
QVERIFY(selectedDate != object.selectedDate());
object.setDateRange(QDate(2006,1,1), QDate(2006,2,28));
object.setSelectedDate(QDate(2006,1,1));
object.showSelectedDate();
button = object.findChild<QToolButton *>("qt_calendar_prevmonth");
QTest::mouseClick(button, Qt::LeftButton);
QCOMPARE(1, object.monthShown());
button = object.findChild<QToolButton *>("qt_calendar_nextmonth");
QTest::mouseClick(button, Qt::LeftButton);
QCOMPARE(2, object.monthShown());
QTest::mouseClick(button, Qt::LeftButton);
QCOMPARE(2, object.monthShown());
}
示例3: selectDate
void QgsAttributeEditor::selectDate()
{
QPushButton *pb = qobject_cast<QPushButton *>( sender() );
if ( !pb )
return;
QWidget *hbox = qobject_cast<QWidget *>( pb->parent() );
if ( !hbox )
return;
QLineEdit *le = hbox->findChild<QLineEdit *>();
if ( !le )
return;
QDialog *dlg = new QDialog();
dlg->setWindowTitle( tr( "Select a date" ) );
QVBoxLayout *vl = new QVBoxLayout( dlg );
QCalendarWidget *cw = new QCalendarWidget( dlg );
cw->setSelectedDate( QDate::fromString( le->text(), Qt::ISODate ) );
vl->addWidget( cw );
QDialogButtonBox *buttonBox = new QDialogButtonBox( dlg );
buttonBox->addButton( QDialogButtonBox::Ok );
buttonBox->addButton( QDialogButtonBox::Cancel );
vl->addWidget( buttonBox );
connect( buttonBox, SIGNAL( accepted() ), dlg, SLOT( accept() ) );
connect( buttonBox, SIGNAL( rejected() ), dlg, SLOT( reject() ) );
if ( dlg->exec() == QDialog::Accepted )
{
le->setText( cw->selectedDate().toString( Qt::ISODate ) );
}
}
示例4: getDate
QDate QtopiaInputDialog::getDate(QWidget *parent, const QString &title, const QString &label, const QDate &date,
const QDate &minDate, const QDate &maxDate, bool *ok)
{
#ifdef CALENDAR_FOR_DATE
QCalendarWidget *cal = new QCalendarWidget();
cal->setSelectedDate(date);
cal->setMinimumDate(minDate);
cal->setMaximumDate(maxDate);
cal->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
QTextCharFormat headerFormat = cal->headerTextFormat();
headerFormat.setBackground(QApplication::palette().window());
headerFormat.setForeground(QApplication::palette().windowText());
cal->setHeaderTextFormat(headerFormat);
QWidget *navBar = cal->findChild<QWidget*>("qt_calendar_navigationbar");
if (navBar)
navBar->setBackgroundRole(QPalette::Window);
QtopiaInputDialog dlg(parent, title, label, cal);
bool accepted = (QtopiaApplication::execDialog(&dlg) == QDialog::Accepted);
if (ok)
*ok = accepted;
return cal->selectedDate();
#else
QDateEdit *de = new QDateEdit(date);
de->setMinimumDate(minDate);
de->setMaximumDate(maxDate);
QtopiaInputDialog dlg(parent, title, label, de);
bool accepted = (QtopiaApplication::execDialog(&dlg) == QDialog::Accepted);
if (ok)
*ok = accepted;
return de->date();
#endif
}
示例5: activated
void LXQtWorldClock::activated(ActivationReason reason)
{
switch (reason)
{
case ILXQtPanelPlugin::Trigger:
case ILXQtPanelPlugin::MiddleClick:
break;
default:
return;
}
if (!mPopup)
{
mPopup = new LXQtWorldClockPopup(mContent);
connect(mPopup, SIGNAL(deactivated()), SLOT(deletePopup()));
if (reason == ILXQtPanelPlugin::Trigger)
{
mPopup->setObjectName(QLatin1String("WorldClockCalendar"));
mPopup->layout()->setContentsMargins(0, 0, 0, 0);
QCalendarWidget *calendarWidget = new QCalendarWidget(mPopup);
mPopup->layout()->addWidget(calendarWidget);
QString timeZoneName = mActiveTimeZone;
if (timeZoneName == QLatin1String("local"))
timeZoneName = QString::fromLatin1(QTimeZone::systemTimeZoneId());
QTimeZone timeZone(timeZoneName.toLatin1());
calendarWidget->setFirstDayOfWeek(QLocale(QLocale::AnyLanguage, timeZone.country()).firstDayOfWeek());
calendarWidget->setSelectedDate(QDateTime::currentDateTime().toTimeZone(timeZone).date());
}
else
{
mPopup->setObjectName(QLatin1String("WorldClockPopup"));
mPopupContent = new QLabel(mPopup);
mPopup->layout()->addWidget(mPopupContent);
mPopupContent->setAlignment(mContent->alignment());
updatePopupContent();
}
mPopup->adjustSize();
mPopup->setGeometry(calculatePopupWindowPos(mPopup->size()));
willShowWindow(mPopup);
mPopup->show();
}
else
{
deletePopup();
}
}
示例6: main
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QCalendarWidget calendar;
calendar.setSelectedDate(calendar.selectedDate().addDays(3));
calendar.setGridVisible(true);
calendar.show();
QCalendarWidget calendarMin;
calendarMin.setMinimumDate(calendarMin.selectedDate().addDays(-7));
calendarMin.setGridVisible(true);
calendarMin.show();
QCalendarWidget calendarMax;
calendarMax.setMaximumDate(calendarMax.selectedDate().addDays(7));
calendarMax.setGridVisible(true);
calendarMax.show();
return app.exec();
}
示例7: showPrevNext
void tst_QCalendarWidget::showPrevNext()
{
QFETCH(ShowFunc, function);
QFETCH(QDate, dateOrigin);
QFETCH(QDate, expectedDate);
QCalendarWidget calWidget;
calWidget.show();
QVERIFY(QTest::qWaitForWindowExposed(&calWidget));
if(!dateOrigin.isNull()) {
calWidget.setSelectedDate(dateOrigin);
calWidget.setCurrentPage(dateOrigin.year(), dateOrigin.month());
QCOMPARE(calWidget.yearShown(), dateOrigin.year());
QCOMPARE(calWidget.monthShown(), dateOrigin.month());
} else {
QCOMPARE(calWidget.yearShown(), QDate::currentDate().year());
QCOMPARE(calWidget.monthShown(), QDate::currentDate().month());
}
(calWidget.*function)();
QCOMPARE(calWidget.yearShown(), expectedDate.year());
QCOMPARE(calWidget.monthShown(), expectedDate.month());
// QTBUG-4058
QTest::qWait(20);
QToolButton *button = calWidget.findChild<QToolButton *>("qt_calendar_prevmonth");
QTest::mouseClick(button, Qt::LeftButton);
expectedDate = expectedDate.addMonths(-1);
QCOMPARE(calWidget.yearShown(), expectedDate.year());
QCOMPARE(calWidget.monthShown(), expectedDate.month());
if(!dateOrigin.isNull()) {
//the selectedDate should not have changed
QCOMPARE(calWidget.selectedDate(), dateOrigin);
}
}
示例8: setValue
//.........这里部分代码省略.........
return false;
sl->setValue( value.toInt() );
}
break;
}
else if ( myFieldType == QVariant::Double )
{
QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox *>( editor );
if ( !dsb )
return false;
dsb->setValue( value.toDouble() );
}
}
case QgsVectorLayer::CheckBox:
{
QGroupBox *gb = qobject_cast<QGroupBox *>( editor );
if ( gb )
{
QPair<QString, QString> states = vl->checkedState( idx );
gb->setChecked( value == states.first );
break;
}
QCheckBox *cb = qobject_cast<QCheckBox *>( editor );
if ( cb )
{
QPair<QString, QString> states = vl->checkedState( idx );
cb->setChecked( value == states.first );
break;
}
}
// fall-through
case QgsVectorLayer::LineEdit:
case QgsVectorLayer::UniqueValuesEditable:
case QgsVectorLayer::Immutable:
case QgsVectorLayer::UuidGenerator:
default:
{
QLineEdit *le = qobject_cast<QLineEdit *>( editor );
QComboBox *cb = qobject_cast<QComboBox *>( editor );
QTextEdit *te = qobject_cast<QTextEdit *>( editor );
QPlainTextEdit *pte = qobject_cast<QPlainTextEdit *>( editor );
if ( !le && ! cb && !te && !pte )
return false;
QString text;
if ( value.isNull() )
{
if ( myFieldType == QVariant::Int || myFieldType == QVariant::Double || myFieldType == QVariant::LongLong )
text = "";
else if ( editType == QgsVectorLayer::UuidGenerator )
text = QUuid::createUuid().toString();
else
text = nullValue;
}
else
{
text = value.toString();
}
if ( le )
le->setText( text );
if ( cb && cb->isEditable() )
cb->setEditText( text );
if ( te )
te->setHtml( text );
if ( pte )
pte->setPlainText( text );
}
break;
case QgsVectorLayer::FileName:
case QgsVectorLayer::Calendar:
{
QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( editor );
if ( cw )
{
cw->setSelectedDate( value.toDate() );
break;
}
QLineEdit* le = qobject_cast<QLineEdit*>( editor );
if ( !le )
{
le = editor->findChild<QLineEdit *>();
}
if ( !le )
{
return false;
}
le->setText( value.toString() );
}
break;
}
return true;
}