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 () ); }
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); } }