Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdatetimeedit.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <private/qapplication_p.h>
5#include <private/qdatetimeedit_p.h>
6#include <qabstractspinbox.h>
7#include <qapplication.h>
8#include <qdatetimeedit.h>
9#include <qdebug.h>
10#include <qevent.h>
11#include <qlineedit.h>
12#include <private/qlineedit_p.h>
13#include <qlocale.h>
14#include <qpainter.h>
15#include <qlayout.h>
16#include <qset.h>
17#include <qstyle.h>
18#include <qstylepainter.h>
19
20#include <algorithm>
21
22//#define QDATETIMEEDIT_QDTEDEBUG
23#ifdef QDATETIMEEDIT_QDTEDEBUG
24# define QDTEDEBUG qDebug() << QString::fromLatin1("%1:%2").arg(__FILE__).arg(__LINE__)
25# define QDTEDEBUGN qDebug
26#else
27# define QDTEDEBUG if (false) qDebug()
28# define QDTEDEBUGN if (false) qDebug
29#endif
30
32
33using namespace Qt::StringLiterals;
34
35// --- QDateTimeEdit ---
36
141{
142 Q_D(QDateTimeEdit);
143 d->init(QDATETIMEEDIT_DATE_INITIAL.startOfDay());
144}
145
153{
154 Q_D(QDateTimeEdit);
155 d->init(datetime.isValid() ? datetime : QDATETIMEEDIT_DATE_INITIAL.startOfDay());
156}
157
171
185
192 parent)
193{
194 Q_D(QDateTimeEdit);
195 d->parserType = parserType;
196 d->init(var);
197}
198
205
226{
227 Q_D(const QDateTimeEdit);
228 return d->value.toDateTime();
229}
230
232{
233 Q_D(QDateTimeEdit);
234 if (datetime.isValid()) {
235 QDateTime when = d->convertTimeZone(datetime);
236 Q_ASSERT(when.timeRepresentation() == d->timeZone);
237
238 d->clearCache();
239 const QDate date = when.date();
240 if (!(d->sections & DateSections_Mask))
242 d->setValue(when, EmitIfChanged);
243 }
244}
245
259{
260 Q_D(const QDateTimeEdit);
261 return d->value.toDate();
262}
263
265{
266 Q_D(QDateTimeEdit);
267 if (date.isValid()) {
268 if (!(d->sections & DateSections_Mask))
270
271 d->clearCache();
272 QDateTime when = d->dateTimeValue(date, d->value.toTime());
273 Q_ASSERT(when.isValid());
274 d->setValue(when, EmitIfChanged);
275 d->updateTimeZone();
276 }
277}
278
292{
293 Q_D(const QDateTimeEdit);
294 return d->value.toTime();
295}
296
298{
299 Q_D(QDateTimeEdit);
300 if (time.isValid()) {
301 d->clearCache();
302 d->setValue(d->dateTimeValue(d->value.toDate(), time), EmitIfChanged);
303 }
304}
305
314{
315 Q_D(const QDateTimeEdit);
316 return d->calendar;
317}
318
330{
331 Q_D(QDateTimeEdit);
332 // Set invalid date time to prevent runtime crashes on calendar change
333 QDateTime previousValue = d->value.toDateTime();
335 d->setCalendar(calendar);
336 setDateTime(previousValue);
337}
338
361{
362 Q_D(const QDateTimeEdit);
363 return d->minimum.toDateTime();
364}
365
370
372{
373 Q_D(QDateTimeEdit);
374 if (dt.isValid() && dt.date() >= QDATETIMEEDIT_DATE_MIN) {
375 const QDateTime m = dt.toTimeZone(d->timeZone);
376 const QDateTime max = d->maximum.toDateTime();
377 d->setRange(m, (max > m ? max : m));
378 }
379}
380
403{
404 Q_D(const QDateTimeEdit);
405 return d->maximum.toDateTime();
406}
407
412
414{
415 Q_D(QDateTimeEdit);
416 if (dt.isValid() && dt.date() <= QDATETIMEEDIT_DATE_MAX) {
417 const QDateTime m = dt.toTimeZone(d->timeZone);
418 const QDateTime min = d->minimum.toDateTime();
419 d->setRange((min < m ? min : m), m);
420 }
421}
422
448{
449 Q_D(QDateTimeEdit);
450 // FIXME: does none of the range checks applied to setMin/setMax methods !
451 const QDateTime minimum = min.toTimeZone(d->timeZone);
452 const QDateTime maximum = (min > max ? minimum : max.toTimeZone(d->timeZone));
453 d->setRange(minimum, maximum);
454}
455
479{
480 Q_D(const QDateTimeEdit);
481 return d->minimum.toDate();
482}
483
485{
486 Q_D(QDateTimeEdit);
487 if (min.isValid() && min >= QDATETIMEEDIT_DATE_MIN)
488 setMinimumDateTime(d->dateTimeValue(min, d->minimum.toTime()));
489}
490
495
519{
520 Q_D(const QDateTimeEdit);
521 return d->maximum.toDate();
522}
523
525{
526 Q_D(QDateTimeEdit);
527 if (max.isValid())
528 setMaximumDateTime(d->dateTimeValue(max, d->maximum.toTime()));
529}
530
535
557{
558 Q_D(const QDateTimeEdit);
559 return d->minimum.toTime();
560}
561
563{
564 Q_D(QDateTimeEdit);
565 if (min.isValid())
566 setMinimumDateTime(d->dateTimeValue(d->minimum.toDate(), min));
567}
568
573
594{
595 Q_D(const QDateTimeEdit);
596 return d->maximum.toTime();
597}
598
600{
601 Q_D(QDateTimeEdit);
602 if (max.isValid())
603 setMaximumDateTime(d->dateTimeValue(d->maximum.toDate(), max));
604}
605
610
638{
639 Q_D(QDateTimeEdit);
640 if (min.isValid() && max.isValid()) {
641 setDateTimeRange(d->dateTimeValue(min, d->minimum.toTime()),
642 d->dateTimeValue(max, d->maximum.toTime()));
643 }
644}
645
677{
678 Q_D(QDateTimeEdit);
679 if (min.isValid() && max.isValid()) {
680 setDateTimeRange(d->dateTimeValue(d->minimum.toDate(), min),
681 d->dateTimeValue(d->maximum.toDate(), max));
682 }
683}
684
695QDateTimeEdit::Sections QDateTimeEdit::displayedSections() const
696{
697 Q_D(const QDateTimeEdit);
698 return d->sections;
699}
700
708{
709 Q_D(const QDateTimeEdit);
710#ifdef QT_KEYPAD_NAVIGATION
711 if (QApplicationPrivate::keypadNavigationEnabled() && d->focusOnButton)
712 return NoSection;
713#endif
714 return QDateTimeEditPrivate::convertToPublic(d->sectionType(d->currentSectionIndex));
715}
716
718{
719 Q_D(QDateTimeEdit);
720 if (section == NoSection || !(section & d->sections))
721 return;
722
723 d->updateCache(d->value, d->displayText());
724 const int size = d->sectionNodes.size();
725 int index = d->currentSectionIndex + 1;
726 for (int i=0; i<2; ++i) {
727 while (index < size) {
728 if (QDateTimeEditPrivate::convertToPublic(d->sectionType(index)) == section) {
729 d->edit->setCursorPosition(d->sectionPos(index));
730 QDTEDEBUG << d->sectionPos(index);
731 return;
732 }
733 ++index;
734 }
735 index = 0;
736 }
737}
738
750{
751 Q_D(const QDateTimeEdit);
752 if (index < 0 || index >= d->sectionNodes.size())
753 return NoSection;
754 return QDateTimeEditPrivate::convertToPublic(d->sectionType(index));
755}
756
767{
768 Q_D(const QDateTimeEdit);
769 return d->sectionNodes.size();
770}
771
772
788{
789 Q_D(const QDateTimeEdit);
790 return d->currentSectionIndex;
791}
792
794{
795 Q_D(QDateTimeEdit);
796 if (index < 0 || index >= d->sectionNodes.size())
797 return;
798 d->edit->setCursorPosition(d->sectionPos(index));
799}
800
812{
813 Q_D(const QDateTimeEdit);
814 if (!d->calendarPopup || !(d->sections & QDateTimeParser::DateSectionMask))
815 return nullptr;
816 if (!d->monthCalendar) {
817 const_cast<QDateTimeEditPrivate*>(d)->initCalendarPopup();
818 }
819 return d->monthCalendar->calendarWidget();
820}
821
832{
833 Q_D(QDateTimeEdit);
835 qWarning("QDateTimeEdit::setCalendarWidget: Cannot set a null calendar widget");
836 return;
837 }
838
839 if (Q_UNLIKELY(!d->calendarPopup)) {
840 qWarning("QDateTimeEdit::setCalendarWidget: calendarPopup is set to false");
841 return;
842 }
843
844 if (Q_UNLIKELY(!(d->display & QDateTimeParser::DateSectionMask))) {
845 qWarning("QDateTimeEdit::setCalendarWidget: no date sections specified");
846 return;
847 }
848 d->initCalendarPopup(calendarWidget);
849}
850
851
865{
866 Q_D(QDateTimeEdit);
867 if (section == NoSection) {
868 d->edit->setSelection(d->edit->cursorPosition(), 0);
869 } else if (section & d->sections) {
870 if (currentSection() != section)
871 setCurrentSection(section);
872 d->setSelected(d->currentSectionIndex);
873 }
874}
875
876
877
887{
888 Q_D(const QDateTimeEdit);
889 if (section == QDateTimeEdit::NoSection || !(section & d->sections)) {
890 return QString();
891 }
892
893 d->updateCache(d->value, d->displayText());
894 const int sectionIndex = d->absoluteIndex(section, 0);
895 return d->sectionText(sectionIndex);
896}
897
924{
925 Q_D(const QDateTimeEdit);
926 return isRightToLeft() ? d->unreversedFormat : d->displayFormat;
927}
928
930{
931 Q_D(QDateTimeEdit);
932 if (d->parseFormat(format)) {
933 d->unreversedFormat.clear();
934 if (isRightToLeft()) {
935 d->unreversedFormat = format;
936 d->displayFormat.clear();
937 for (int i=d->sectionNodes.size() - 1; i>=0; --i) {
938 d->displayFormat += d->separators.at(i + 1);
939 d->displayFormat += d->sectionNode(i).format();
940 }
941 d->displayFormat += d->separators.at(0);
942 std::reverse(d->separators.begin(), d->separators.end());
943 std::reverse(d->sectionNodes.begin(), d->sectionNodes.end());
944 }
945
946 d->formatExplicitlySet = true;
947 d->sections = QDateTimeEditPrivate::convertSections(d->display);
948 d->clearCache();
949
950 d->currentSectionIndex = qMin(d->currentSectionIndex, d->sectionNodes.size() - 1);
951 const bool timeShown = (d->sections & TimeSections_Mask);
952 const bool dateShown = (d->sections & DateSections_Mask);
953 Q_ASSERT(dateShown || timeShown);
954 if (timeShown && !dateShown) {
955 QTime time = d->value.toTime();
956 setDateRange(d->value.toDate(), d->value.toDate());
957 if (d->minimum.toTime() >= d->maximum.toTime()) {
959 // if the time range became invalid during the adjustment, the time would have been reset
960 setTime(time);
961 }
962 } else if (dateShown && !timeShown) {
964 d->value = d->value.toDate().startOfDay(d->timeZone);
965 }
966 d->updateEdit();
967 d->editorCursorPositionChanged(-1, 0);
968 }
969}
970
983{
984 Q_D(const QDateTimeEdit);
985 return d->calendarPopup;
986}
987
989{
990 Q_D(QDateTimeEdit);
991 if (enable == d->calendarPopup)
992 return;
994 d->calendarPopup = enable;
995#ifdef QT_KEYPAD_NAVIGATION
996 if (!enable)
997 d->focusOnButton = false;
998#endif
999 d->updateEditFieldGeometry();
1000 update();
1001}
1002
1003#if QT_DEPRECATED_SINCE(6, 10)
1015Qt::TimeSpec QDateTimeEdit::timeSpec() const
1016{
1017 Q_D(const QDateTimeEdit);
1018 return d->timeZone.timeSpec();
1019}
1020
1021void QDateTimeEdit::setTimeSpec(Qt::TimeSpec spec)
1022{
1023 Q_D(QDateTimeEdit);
1024 if (spec != d->timeZone.timeSpec()) {
1025 switch (spec) {
1026 case Qt::UTC:
1028 break;
1029 case Qt::LocalTime:
1031 break;
1032 default:
1033 qWarning() << "Ignoring attempt to set time-spec" << spec
1034 << "which needs ancillary data: see setTimeZone()";
1035 return;
1036 }
1037 }
1038}
1039#endif // 6.10 deprecation
1040
1041// TODO: enable user input to control timeZone, when the format includes it.
1056{
1057 Q_D(const QDateTimeEdit);
1058 return d->timeZone;
1059}
1060
1062{
1063 Q_D(QDateTimeEdit);
1064 if (zone != d->timeZone) {
1065 d->timeZone = zone;
1066 d->updateTimeZone();
1067 }
1068}
1069
1075{
1076 Q_D(const QDateTimeEdit);
1077 if (d->cachedSizeHint.isEmpty()) {
1079
1080 const QFontMetrics fm(fontMetrics());
1081 int h = d->edit->sizeHint().height();
1082 int w = 0;
1083 QString s;
1084 s = d->textFromValue(d->minimum) + u' ';
1085 w = qMax<int>(w, fm.horizontalAdvance(s));
1086 s = d->textFromValue(d->maximum) + u' ';
1087 w = qMax<int>(w, fm.horizontalAdvance(s));
1088 if (d->specialValueText.size()) {
1089 s = d->specialValueText;
1090 w = qMax<int>(w, fm.horizontalAdvance(s));
1091 }
1092 w += 2; // cursor blinking space
1093
1094 QSize hint(w, h);
1095
1096#ifdef Q_OS_MAC
1097 if (d->calendarPopupEnabled()) {
1099 d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_ComboBox, &opt, hint, this);
1100 } else
1101#endif
1102 {
1103 QStyleOptionSpinBox opt;
1105 d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this);
1106 }
1107
1108 d->cachedMinimumSizeHint = d->cachedSizeHint;
1109 // essentially make minimumSizeHint return the same as sizeHint for datetimeedits
1110 }
1111 return d->cachedSizeHint;
1112}
1113
1114
1120{
1121 Q_D(QDateTimeEdit);
1122 switch (event->type()) {
1124 const bool was = d->formatExplicitlySet;
1125 const QString oldFormat = d->displayFormat;
1126 d->displayFormat.clear();
1127 setDisplayFormat(oldFormat);
1128 d->formatExplicitlySet = was;
1129 break; }
1131 d->updateEdit();
1132 break;
1134#ifdef Q_OS_MAC
1136#endif
1137 d->setLayoutItemMargins(QStyle::SE_DateTimeEditLayoutItem);
1138 break;
1139 default:
1140 break;
1141 }
1143}
1144
1150{
1151 Q_D(QDateTimeEdit);
1152 d->clearSection(d->currentSectionIndex);
1153}
1159{
1160 Q_D(QDateTimeEdit);
1161 int oldCurrent = d->currentSectionIndex;
1162 bool select = true;
1163 bool inserted = false;
1164
1165 switch (event->key()) {
1166#ifdef QT_KEYPAD_NAVIGATION
1167 case Qt::Key_NumberSign: //shortcut to popup calendar
1168 if (QApplicationPrivate::keypadNavigationEnabled() && d->calendarPopupEnabled()) {
1169 d->initCalendarPopup();
1170 d->positionCalendarPopup();
1171 d->monthCalendar->show();
1172 return;
1173 }
1174 break;
1175 case Qt::Key_Select:
1176 if (QApplicationPrivate::keypadNavigationEnabled()) {
1177 if (hasEditFocus()) {
1178 if (d->focusOnButton) {
1179 d->initCalendarPopup();
1180 d->positionCalendarPopup();
1181 d->monthCalendar->show();
1182 d->focusOnButton = false;
1183 return;
1184 }
1185 setEditFocus(false);
1186 selectAll();
1187 } else {
1188 setEditFocus(true);
1189
1190 //hide cursor
1191 d->edit->d_func()->setCursorVisible(false);
1192 d->edit->d_func()->control->setBlinkingCursorEnabled(false);
1193 d->setSelected(0);
1194 }
1195 }
1196 return;
1197#endif
1198 case Qt::Key_Enter:
1199 case Qt::Key_Return:
1200 d->interpret(AlwaysEmit);
1201 d->setSelected(d->currentSectionIndex, true);
1202 event->ignore();
1204 emit d->edit->returnPressed();
1205 return;
1206 default:
1207#ifdef QT_KEYPAD_NAVIGATION
1208 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()
1209 && !event->text().isEmpty() && event->text().at(0).isLetterOrNumber()) {
1210 setEditFocus(true);
1211
1212 //hide cursor
1213 d->edit->d_func()->setCursorVisible(false);
1214 d->edit->d_func()->control->setBlinkingCursorEnabled(false);
1215 d->setSelected(0);
1216 oldCurrent = 0;
1217 }
1218#endif
1219 if (!d->isSeparatorKey(event)) {
1220 inserted = select = !event->text().isEmpty() && event->text().at(0).isPrint()
1221 && !(event->modifiers() & ~(Qt::ShiftModifier|Qt::KeypadModifier));
1222 break;
1223 }
1224 Q_FALLTHROUGH();
1225 case Qt::Key_Left:
1226 case Qt::Key_Right:
1227 if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right) {
1228 if (
1229#ifdef QT_KEYPAD_NAVIGATION
1230 QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()
1231 || !QApplicationPrivate::keypadNavigationEnabled() &&
1232#endif
1233 !(event->modifiers() & Qt::ControlModifier)) {
1234 select = false;
1235 break;
1236 }
1237 }
1238 Q_FALLTHROUGH();
1239 case Qt::Key_Backtab:
1240 case Qt::Key_Tab: {
1241 event->accept();
1242 if (d->specialValue()) {
1243 d->edit->setSelection(d->edit->cursorPosition(), 0);
1244 return;
1245 }
1246 const bool forward = event->key() != Qt::Key_Left && event->key() != Qt::Key_Backtab
1247 && (event->key() != Qt::Key_Tab || !(event->modifiers() & Qt::ShiftModifier));
1248#ifdef QT_KEYPAD_NAVIGATION
1249 int newSection = d->nextPrevSection(d->currentSectionIndex, forward);
1250 if (QApplicationPrivate::keypadNavigationEnabled()) {
1251 if (d->focusOnButton) {
1252 newSection = forward ? 0 : d->sectionNodes.size() - 1;
1253 d->focusOnButton = false;
1254 update();
1255 } else if (newSection < 0 && select && d->calendarPopupEnabled()) {
1257 d->focusOnButton = true;
1258 update();
1259 return;
1260 }
1261 }
1262 // only allow date/time sections to be selected.
1264 return;
1265#endif
1266 //key tab and backtab will be managed thrgout QWidget::event
1267 if (event->key() != Qt::Key_Backtab && event->key() != Qt::Key_Tab)
1268 focusNextPrevChild(forward);
1269
1270 return; }
1271 }
1273 if (select && !d->edit->hasSelectedText()) {
1274 if (inserted && d->sectionAt(d->edit->cursorPosition()) == QDateTimeParser::NoSectionIndex) {
1275 QString str = d->displayText();
1276 int pos = d->edit->cursorPosition();
1278 && (d->sectionNodes.at(oldCurrent).count != 1
1279 || d->sectionMaxSize(oldCurrent) == d->sectionSize(oldCurrent)
1280 || d->skipToNextSection(oldCurrent, d->value.toDateTime(), d->sectionText(oldCurrent)))) {
1281 QDTEDEBUG << "Setting currentsection to"
1282 << d->closestSection(d->edit->cursorPosition(), true) << event->key()
1283 << oldCurrent << str;
1284 const int tmp = d->closestSection(d->edit->cursorPosition(), true);
1285 if (tmp >= 0)
1286 d->currentSectionIndex = tmp;
1287 }
1288 }
1289 if (d->currentSectionIndex != oldCurrent) {
1290 d->setSelected(d->currentSectionIndex);
1291 }
1292 }
1293 if (d->specialValue()) {
1294 d->edit->setSelection(d->edit->cursorPosition(), 0);
1295 }
1296}
1297
1302#if QT_CONFIG(wheelevent)
1303void QDateTimeEdit::wheelEvent(QWheelEvent *event)
1304{
1305 QAbstractSpinBox::wheelEvent(event);
1306}
1307#endif
1308
1314{
1315 Q_D(QDateTimeEdit);
1317 const int oldPos = d->edit->cursorPosition();
1318 if (!d->formatExplicitlySet) {
1319 QString *frm = nullptr;
1320 if (d->displayFormat == d->defaultTimeFormat) {
1321 frm = &d->defaultTimeFormat;
1322 } else if (d->displayFormat == d->defaultDateFormat) {
1323 frm = &d->defaultDateFormat;
1324 } else if (d->displayFormat == d->defaultDateTimeFormat) {
1325 frm = &d->defaultDateTimeFormat;
1326 }
1327
1328 if (frm) {
1329 d->readLocaleSettings();
1330 if (d->displayFormat != *frm) {
1331 setDisplayFormat(*frm);
1332 d->formatExplicitlySet = false;
1333 d->edit->setCursorPosition(oldPos);
1334 }
1335 }
1336 }
1337 const bool oldHasHadFocus = d->hasHadFocus;
1338 d->hasHadFocus = true;
1339 bool first = true;
1340 switch (event->reason()) {
1342 first = false;
1343 break;
1346 return;
1348 if (oldHasHadFocus)
1349 return;
1350 break;
1352 case Qt::TabFocusReason:
1353 default:
1354 break;
1355 }
1356 if (isRightToLeft())
1357 first = !first;
1358 d->updateEdit(); // needed to make it update specialValueText
1359
1360 d->setSelected(first ? 0 : d->sectionNodes.size() - 1);
1361}
1362
1368{
1369 Q_D(QDateTimeEdit);
1370 const int newSection = d->nextPrevSection(d->currentSectionIndex, next);
1371 switch (d->sectionType(newSection)) {
1376 default:
1377 d->edit->deselect();
1378 d->edit->setCursorPosition(d->sectionPos(newSection));
1379 QDTEDEBUG << d->sectionPos(newSection);
1380 d->setSelected(newSection, true);
1381 return false;
1382 }
1383}
1384
1390{
1391 Q_D(QDateTimeEdit);
1392#ifdef QT_KEYPAD_NAVIGATION
1393 // with keypad navigation and not editFocus, left right change the date/time by a fixed amount.
1394 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
1395 // if date based, shift by day. else shift by 15min
1396 if (d->sections & DateSections_Mask) {
1397 setDateTime(dateTime().addDays(steps));
1398 } else {
1399 int minutes = time().hour()*60 + time().minute();
1400 int blocks = minutes/15;
1401 blocks += steps;
1402 /* rounding involved */
1403 if (minutes % 15) {
1404 if (steps < 0) {
1405 blocks += 1; // do one less step;
1406 }
1407 }
1408
1409 minutes = blocks * 15;
1410
1411 /* need to take wrapping into account */
1412 if (!d->wrapping) {
1413 int max_minutes = d->maximum.toTime().hour()*60 + d->maximum.toTime().minute();
1414 int min_minutes = d->minimum.toTime().hour()*60 + d->minimum.toTime().minute();
1415
1416 if (minutes >= max_minutes) {
1418 return;
1419 } else if (minutes <= min_minutes) {
1421 return;
1422 }
1423 }
1424 setTime(QTime(minutes/60, minutes%60));
1425 }
1426 return;
1427 }
1428#endif
1429 // don't optimize away steps == 0. This is the only way to select
1430 // the currentSection in Qt 4.1.x
1431 if (d->specialValue() && displayedSections() != AmPmSection) {
1432 for (int i=0; i<d->sectionNodes.size(); ++i) {
1433 if (d->sectionType(i) != QDateTimeParser::AmPmSection) {
1434 d->currentSectionIndex = i;
1435 break;
1436 }
1437 }
1438 }
1439 d->setValue(d->stepBy(d->currentSectionIndex, steps, false), EmitIfChanged);
1440 d->updateCache(d->value, d->displayText());
1441
1442 d->setSelected(d->currentSectionIndex);
1443 d->updateTimeZone();
1444}
1445
1455{
1456 Q_D(const QDateTimeEdit);
1457 return locale().toString(dateTime, d->displayFormat, d->calendar);
1458}
1459
1460
1470{
1471 Q_D(const QDateTimeEdit);
1472 QString copy = text;
1473 int pos = d->edit->cursorPosition();
1475 return d->validateAndInterpret(copy, pos, state);
1476}
1477
1483{
1484 Q_D(const QDateTimeEdit);
1486 d->validateAndInterpret(text, pos, state);
1487 return state;
1488}
1489
1496{
1497 Q_D(const QDateTimeEdit);
1499 int copy = d->edit->cursorPosition();
1500
1501 QDateTime value = d->validateAndInterpret(input, copy, state, true);
1502 // CorrectToPreviousValue correction is handled by QAbstractSpinBox.
1503 // The value might not match the input if the input represents a date-time
1504 // skipped over by its time representation, such as a spring-forward.
1505 if (d->correctionMode == QAbstractSpinBox::CorrectToNearestValue)
1507}
1508
1509
1514QDateTimeEdit::StepEnabled QDateTimeEdit::stepEnabled() const
1515{
1516 Q_D(const QDateTimeEdit);
1517 if (d->readOnly)
1518 return {};
1519 if (d->specialValue()) {
1520 return (d->minimum == d->maximum ? StepEnabled{} : StepEnabled(StepUpEnabled));
1521 }
1522
1523 QAbstractSpinBox::StepEnabled ret = { };
1524
1525#ifdef QT_KEYPAD_NAVIGATION
1526 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
1527 if (d->wrapping)
1528 return StepEnabled(StepUpEnabled | StepDownEnabled);
1529 // 3 cases. date, time, datetime. each case look
1530 // at just the relevant component.
1531 QVariant max, min, val;
1532 if (!(d->sections & DateSections_Mask)) {
1533 // time only, no date
1534 max = d->maximum.toTime();
1535 min = d->minimum.toTime();
1536 val = d->value.toTime();
1537 } else if (!(d->sections & TimeSections_Mask)) {
1538 // date only, no time
1539 max = d->maximum.toDate();
1540 min = d->minimum.toDate();
1541 val = d->value.toDate();
1542 } else {
1543 // both
1544 max = d->maximum;
1545 min = d->minimum;
1546 val = d->value;
1547 }
1548 if (val != min)
1550 if (val != max)
1552 return ret;
1553 }
1554#endif
1555 switch (d->sectionType(d->currentSectionIndex)) {
1558 case QDateTimeParser::LastSection: return { };
1559 default: break;
1560 }
1561 if (d->wrapping)
1562 return StepEnabled(StepDownEnabled|StepUpEnabled);
1563
1564 QVariant v = d->stepBy(d->currentSectionIndex, 1, true);
1565 if (v != d->value) {
1567 }
1568 v = d->stepBy(d->currentSectionIndex, -1, true);
1569 if (v != d->value) {
1571 }
1572
1573 return ret;
1574}
1575
1576
1582{
1583 Q_D(QDateTimeEdit);
1584 if (!d->calendarPopupEnabled()) {
1586 return;
1587 }
1588 d->updateHoverControl(event->position().toPoint());
1589 if (d->hoverControl == QStyle::SC_ComboBoxArrow) {
1590 event->accept();
1591 if (d->readOnly) {
1592 return;
1593 }
1594 d->updateArrow(QStyle::State_Sunken);
1595 d->initCalendarPopup();
1596 d->positionCalendarPopup();
1597 //Show the calendar
1598 d->monthCalendar->show();
1599 } else {
1601 }
1602}
1603
1640
1651
1658
1710
1721
1728
1745// --- QDateTimeEditPrivate ---
1746
1755 timeZone(zone)
1756{
1757 fixday = true;
1758 type = QMetaType::QDateTime;
1760
1761 first.pos = 0;
1765}
1766
1768{
1769 return datetime.toTimeZone(timeZone);
1770}
1771
1776
1778{
1781 value = value.toDateTime().toTimeZone(timeZone);
1782
1783 // time zone changes can lead to 00:00:00 becomes 01:00:00 and 23:59:59 becomes 00:59:59 (invalid range)
1784 const bool dateShown = (sections & QDateTimeEdit::DateSections_Mask);
1785 if (!dateShown) {
1786 if (minimum.toTime() >= maximum.toTime()){
1789 }
1790 }
1791}
1792
1794{
1795 const QString newText = (specialValue() ? specialValueText : textFromValue(value));
1796 if (newText == displayText())
1797 return;
1798 int selsize = edit->selectedText().size();
1799 const QSignalBlocker blocker(edit);
1800
1801 edit->setText(newText);
1802
1803 if (!specialValue()
1804#ifdef QT_KEYPAD_NAVIGATION
1805 && !(QApplicationPrivate::keypadNavigationEnabled() && !edit->hasEditFocus())
1806#endif
1807 ) {
1809 QDTEDEBUG << "cursor is " << cursor << currentSectionIndex;
1810 cursor = qBound(0, cursor, displayText().size());
1811 QDTEDEBUG << cursor;
1812 if (selsize > 0) {
1813 edit->setSelection(cursor, selsize);
1814 QDTEDEBUG << cursor << selsize;
1815 } else {
1817 QDTEDEBUG << cursor;
1818
1819 }
1820 }
1821}
1822
1824{
1825 if (keyboardTracking)
1826 return minimum.toDateTime();
1827
1830
1831 return QDATETIMEEDIT_DATE_MIN.startOfDay(timeZone);
1832}
1833
1835{
1836 if (keyboardTracking)
1837 return maximum.toDateTime();
1838
1841
1842 return QDATETIMEEDIT_DATE_MAX.endOfDay(timeZone);
1843}
1844
1851void QDateTimeEditPrivate::setSelected(int sectionIndex, bool forward)
1852{
1853 if (specialValue()
1854#ifdef QT_KEYPAD_NAVIGATION
1855 || (QApplicationPrivate::keypadNavigationEnabled() && !edit->hasEditFocus())
1856#endif
1857 ) {
1858 edit->selectAll();
1859 } else {
1860 const SectionNode &node = sectionNode(sectionIndex);
1861 if (node.type == NoSection || node.type == LastSection || node.type == FirstSection)
1862 return;
1863
1865 const int size = sectionSize(sectionIndex);
1866 if (forward) {
1868 } else {
1869 edit->setSelection(sectionPos(node) + size, -size);
1870 }
1871 }
1872}
1873
1881{
1882 if (pos < separators.first().size())
1883 return (pos == 0 ? FirstSectionIndex : NoSectionIndex);
1884
1885 const QString text = displayText();
1886 const int textSize = text.size();
1887 if (textSize - pos < separators.last().size() + 1) {
1888 if (separators.last().size() == 0) {
1889 return sectionNodes.size() - 1;
1890 }
1891 return (pos == textSize ? LastSectionIndex : NoSectionIndex);
1892 }
1894
1895 for (int i=0; i<sectionNodes.size(); ++i) {
1896 const int tmp = sectionPos(i);
1897 if (pos < tmp + sectionSize(i)) {
1898 return (pos < tmp ? -1 : i);
1899 }
1900 }
1901 return -1;
1902}
1903
1911int QDateTimeEditPrivate::closestSection(int pos, bool forward) const
1912{
1913 Q_ASSERT(pos >= 0);
1914 if (pos < separators.first().size())
1915 return forward ? 0 : FirstSectionIndex;
1916
1917 const QString text = displayText();
1918 if (text.size() - pos < separators.last().size() + 1)
1919 return forward ? LastSectionIndex : int(sectionNodes.size() - 1);
1920
1922 for (int i=0; i<sectionNodes.size(); ++i) {
1923 const int tmp = sectionPos(sectionNodes.at(i));
1924 if (pos < tmp + sectionSize(i)) {
1925 if (pos < tmp && !forward) {
1926 return i-1;
1927 }
1928 return i;
1929 } else if (i == sectionNodes.size() - 1 && pos > tmp) {
1930 return i;
1931 }
1932 }
1933 qWarning("QDateTimeEdit: Internal Error: closestSection returned NoSection");
1934 return NoSectionIndex;
1935}
1936
1943int QDateTimeEditPrivate::nextPrevSection(int current, bool forward) const
1944{
1945 Q_Q(const QDateTimeEdit);
1946 if (q->isRightToLeft())
1947 forward = !forward;
1948
1949 switch (current) {
1950 case FirstSectionIndex: return forward ? 0 : FirstSectionIndex;
1951 case LastSectionIndex: return (forward ? LastSectionIndex : int(sectionNodes.size() - 1));
1952 case NoSectionIndex: return FirstSectionIndex;
1953 default: break;
1954 }
1955 Q_ASSERT(current >= 0 && current < sectionNodes.size());
1956
1957 current += (forward ? 1 : -1);
1958 if (current >= sectionNodes.size()) {
1959 return LastSectionIndex;
1960 } else if (current < 0) {
1961 return FirstSectionIndex;
1962 }
1963
1964 return current;
1965}
1966
1974{
1975 const auto space = u' ';
1976 int cursorPos = edit->cursorPosition();
1977 const QSignalBlocker blocker(edit);
1978 QString t = edit->text();
1979 const int pos = sectionPos(index);
1980 if (Q_UNLIKELY(pos == -1)) {
1981 qWarning("QDateTimeEdit: Internal error (%s:%d)", __FILE__, __LINE__);
1982 return;
1983 }
1984 const int size = sectionSize(index);
1985 t.replace(pos, size, QString().fill(space, size));
1986 edit->setText(t);
1987 edit->setCursorPosition(cursorPos);
1988 QDTEDEBUG << cursorPos;
1989}
1990
1991
1999{
2000 if (val != cachedValue || str != cachedText || cacheGuard) {
2001 cacheGuard = true;
2002 QString copy = str;
2003 int unused = edit->cursorPosition();
2004 QValidator::State unusedState;
2005 validateAndInterpret(copy, unused, unusedState);
2006 cacheGuard = false;
2007 }
2008}
2009
2017 QValidator::State &state, bool fixup) const
2018{
2019 if (input.isEmpty()) {
2020 if (sectionNodes.size() == 1 || !specialValueText.isEmpty()) {
2022 } else {
2024 }
2025 return getZeroVariant().toDateTime();
2026 } else if (cachedText == input && !fixup) {
2028 return cachedValue.toDateTime();
2029 } else if (!specialValueText.isEmpty()) {
2030 bool changeCase = false;
2031 const int max = qMin(specialValueText.size(), input.size());
2032 int i;
2033 for (i=0; i<max; ++i) {
2034 const QChar ic = input.at(i);
2035 const QChar sc = specialValueText.at(i);
2036 if (ic != sc) {
2037 if (sc.toLower() == ic.toLower()) {
2038 changeCase = true;
2039 } else {
2040 break;
2041 }
2042 }
2043 }
2044 if (i == max) {
2046 if (changeCase) {
2048 }
2049 return minimum.toDateTime();
2050 }
2051 }
2052
2053 StateNode tmp = parse(input, position, value.toDateTime(), fixup);
2054 // Take note of any corrections imposed during parsing:
2055 input = m_text;
2056 // TODO: if the format specifies time-zone, update timeZone to match the
2057 // parsed text; but we're in const context, so can't - QTBUG-118393.
2058 // Impose this widget's time system:
2059 tmp.value = tmp.value.toTimeZone(timeZone);
2060 // ... but that might turn a valid datetime into an invalid one:
2061 if (!tmp.value.isValid() && tmp.state == Acceptable)
2062 tmp.state = Intermediate;
2063
2064 position += tmp.padded;
2065 state = QValidator::State(int(tmp.state));
2067 if (tmp.conflicts && conflictGuard != tmp.value) {
2068 conflictGuard = tmp.value;
2069 clearCache();
2070 input = textFromValue(tmp.value);
2071 updateCache(tmp.value, input);
2073 } else {
2074 cachedText = input;
2076 cachedValue = tmp.value;
2077 }
2078 } else {
2079 clearCache();
2080 }
2081 return (tmp.value.isNull() ? getZeroVariant().toDateTime() : tmp.value);
2082}
2083
2084
2090{
2091 Q_Q(const QDateTimeEdit);
2092 return q->textFromDateTime(f.toDateTime());
2093}
2094
2103{
2104 Q_Q(const QDateTimeEdit);
2105 return q->dateTimeFromText(f).toTimeZone(timeZone);
2106}
2107
2108
2119QDateTime QDateTimeEditPrivate::stepBy(int sectionIndex, int steps, bool test) const
2120{
2121 Q_Q(const QDateTimeEdit);
2122 QDateTime v = value.toDateTime();
2124 int pos = edit->cursorPosition();
2125 const SectionNode sn = sectionNode(sectionIndex);
2126
2127 // to make sure it behaves reasonably when typing something and then stepping in non-tracking mode
2128 if (!test && pendingEmit && q->validate(str, pos) == QValidator::Acceptable)
2129 v = q->dateTimeFromText(str);
2130 int val = getDigit(v, sectionIndex);
2131
2132 const int min = absoluteMin(sectionIndex);
2133 const int max = absoluteMax(sectionIndex, value.toDateTime());
2134
2135 if (sn.type & DayOfWeekSectionMask) {
2136 // Must take locale's first day of week into account when *not*
2137 // wrapping; min and max don't help us.
2138#ifndef QT_ALWAYS_WRAP_WEEKDAY // (documentation, not an actual define)
2139 if (!wrapping) {
2140 /* It's not clear this is ever really a desirable behavior.
2141
2142 It refuses to step backwards from the first day of the week or
2143 forwards from the day before, only allowing day-of-week stepping
2144 from start to end of one week. That's strictly what non-wrapping
2145 behavior must surely mean, when put in locale-neutral terms.
2146
2147 It is, however, likely that users would prefer the "more natural"
2148 behavior of cycling through the week.
2149 */
2150 const int first = int(locale().firstDayOfWeek()); // Mon = 1 through 7 = Sun
2151 val = qBound(val < first ? first - 7 : first,
2152 val + steps,
2153 val < first ? first - 1 : first + 6);
2154 } else
2155#endif
2156 {
2157 val += steps;
2158 }
2159
2160 // Restore to range from 1 through 7:
2161 val = val % 7;
2162 if (val <= 0)
2163 val += 7;
2164 } else {
2165 val += steps;
2166 const int span = max - min + 1;
2167 if (val < min)
2168 val = wrapping ? val + span : min;
2169 else if (val > max)
2170 val = wrapping ? val - span : max;
2171 }
2172
2173 const int oldDay = v.date().day(calendar);
2174
2175 /*
2176 Stepping into a daylight saving time that doesn't exist (setDigit() is
2177 true when date and time are valid, even if the date-time returned
2178 isn't), so use the time that has the same distance from epoch.
2179 */
2180 if (setDigit(v, sectionIndex, val) && getDigit(v, sectionIndex) != val
2181 && sn.type & HourSectionMask && steps < 0) {
2182 // decreasing from e.g 3am to 2am would get us back to 3am, but we want 1am
2183 auto msecsSinceEpoch = v.toMSecsSinceEpoch() - 3600 * 1000;
2184 v = QDateTime::fromMSecsSinceEpoch(msecsSinceEpoch, v.timeRepresentation());
2185 }
2186 // if this sets year or month it will make
2187 // sure that days are lowered if needed.
2188
2189 const QDateTime minimumDateTime = minimum.toDateTime();
2190 const QDateTime maximumDateTime = maximum.toDateTime();
2191 // changing one section should only modify that section, if possible
2192 if (sn.type != AmPmSection && !(sn.type & DayOfWeekSectionMask)
2193 && (v < minimumDateTime || v > maximumDateTime)) {
2194 const int localmin = getDigit(minimumDateTime, sectionIndex);
2195 const int localmax = getDigit(maximumDateTime, sectionIndex);
2196
2197 if (wrapping) {
2198 // just because we hit the roof in one direction, it
2199 // doesn't mean that we hit the floor in the other
2200 if (steps > 0) {
2201 setDigit(v, sectionIndex, min);
2202 if (!(sn.type & DaySectionMask) && sections & DateSectionMask) {
2203 const int daysInMonth = v.date().daysInMonth(calendar);
2204 if (v.date().day(calendar) < oldDay && v.date().day(calendar) < daysInMonth) {
2205 const int adds = qMin(oldDay, daysInMonth);
2206 v = v.addDays(adds - v.date().day(calendar));
2207 }
2208 }
2209
2210 if (v < minimumDateTime) {
2211 setDigit(v, sectionIndex, localmin);
2212 if (v < minimumDateTime)
2213 setDigit(v, sectionIndex, localmin + 1);
2214 }
2215 } else {
2216 setDigit(v, sectionIndex, max);
2217 if (!(sn.type & DaySectionMask) && sections & DateSectionMask) {
2218 const int daysInMonth = v.date().daysInMonth(calendar);
2219 if (v.date().day(calendar) < oldDay && v.date().day(calendar) < daysInMonth) {
2220 const int adds = qMin(oldDay, daysInMonth);
2221 v = v.addDays(adds - v.date().day(calendar));
2222 }
2223 }
2224
2225 if (v > maximumDateTime) {
2226 setDigit(v, sectionIndex, localmax);
2227 if (v > maximumDateTime)
2228 setDigit(v, sectionIndex, localmax - 1);
2229 }
2230 }
2231 } else {
2232 setDigit(v, sectionIndex, (steps > 0 ? localmax : localmin));
2233 }
2234 }
2235 if (!test && oldDay != v.date().day(calendar) && !(sn.type & DaySectionMask)) {
2236 // this should not happen when called from stepEnabled
2237 cachedDay = qMax<int>(oldDay, cachedDay);
2238 }
2239
2240 if (v < minimumDateTime) {
2241 if (wrapping) {
2242 QDateTime t = v;
2243 setDigit(t, sectionIndex, steps < 0 ? max : min);
2244 bool mincmp = (t >= minimumDateTime);
2245 bool maxcmp = (t <= maximumDateTime);
2246 if (!mincmp || !maxcmp) {
2247 setDigit(t, sectionIndex, getDigit(steps < 0
2248 ? maximumDateTime
2249 : minimumDateTime, sectionIndex));
2250 mincmp = (t >= minimumDateTime);
2251 maxcmp = (t <= maximumDateTime);
2252 }
2253 if (mincmp && maxcmp) {
2254 v = t;
2255 }
2256 } else {
2257 v = value.toDateTime();
2258 }
2259 } else if (v > maximumDateTime) {
2260 if (wrapping) {
2261 QDateTime t = v;
2262 setDigit(t, sectionIndex, steps > 0 ? min : max);
2263 bool mincmp = (t >= minimumDateTime);
2264 bool maxcmp = (t <= maximumDateTime);
2265 if (!mincmp || !maxcmp) {
2266 setDigit(t, sectionIndex, getDigit(steps > 0 ?
2267 minimumDateTime :
2268 maximumDateTime, sectionIndex));
2269 mincmp = (t >= minimumDateTime);
2270 maxcmp = (t <= maximumDateTime);
2271 }
2272 if (mincmp && maxcmp) {
2273 v = t;
2274 }
2275 } else {
2276 v = value.toDateTime();
2277 }
2278 }
2279
2280 return bound(v, value, steps).toDateTime().toTimeZone(timeZone);
2281}
2282
2288{
2289 Q_Q(QDateTimeEdit);
2290 if (ep == NeverEmit) {
2291 return;
2292 }
2293 pendingEmit = false;
2294
2295 const bool dodate = value.toDate().isValid() && (sections & DateSectionMask);
2296 const bool datechanged = (ep == AlwaysEmit || old.toDate() != value.toDate());
2297 const bool dotime = value.toTime().isValid() && (sections & TimeSectionMask);
2298 const bool timechanged = (ep == AlwaysEmit || old.toTime() != value.toTime());
2299
2301
2303 if (datechanged || timechanged)
2304 emit q->dateTimeChanged(value.toDateTime());
2305 if (dodate && datechanged)
2306 emit q->dateChanged(value.toDate());
2307 if (dotime && timechanged)
2308 emit q->timeChanged(value.toTime());
2309
2310}
2311
2317{
2319 return;
2320 const QString oldText = displayText();
2321 updateCache(value, oldText);
2322
2323 const bool allowChange = !edit->hasSelectedText();
2324 const bool forward = oldpos <= newpos;
2326 int s = sectionAt(newpos);
2327 if (s == NoSectionIndex && forward && newpos > 0) {
2328 s = sectionAt(newpos - 1);
2329 }
2330
2331 int c = newpos;
2332
2333 const int selstart = edit->selectionStart();
2334 const int selSection = sectionAt(selstart);
2335 const int l = selSection != -1 ? sectionSize(selSection) : 0;
2336
2337 if (s == NoSectionIndex) {
2338 if (l > 0 && selstart == sectionPos(selSection) && edit->selectedText().size() == l) {
2339 s = selSection;
2340 if (allowChange)
2341 setSelected(selSection, true);
2342 c = -1;
2343 } else {
2344 int closest = closestSection(newpos, forward);
2345 c = sectionPos(closest) + (forward ? 0 : qMax<int>(0, sectionSize(closest)));
2346
2347 if (allowChange) {
2349 QDTEDEBUG << c;
2350 }
2351 s = closest;
2352 }
2353 }
2354
2355 if (allowChange && currentSectionIndex != s) {
2357 }
2358 if (c == -1) {
2359 setSelected(s, true);
2360 } else if (!edit->hasSelectedText()) {
2361 if (oldpos < newpos) {
2362 edit->setCursorPosition(displayText().size() - (oldText.size() - c));
2363 } else {
2365 }
2366 }
2367
2368 QDTEDEBUG << "currentSectionIndex is set to" << sectionNode(s).name()
2369 << oldpos << newpos
2370 << "was" << sectionNode(currentSectionIndex).name();
2371
2374 "QDateTimeEditPrivate::editorCursorPositionChanged()",
2375 qPrintable(QString::fromLatin1("Internal error (%1 %2)").
2377 arg(sectionNodes.size())));
2378
2380}
2381
2394
2416
2439
2445{
2446 Q_D(QDateTimeEdit);
2447 if (!d->calendarPopupEnabled()) {
2449 return;
2450 }
2451
2452 QStyleOptionSpinBox opt;
2454
2455 QStyleOptionComboBox optCombo;
2456
2457 optCombo.initFrom(this);
2458 optCombo.editable = true;
2459 optCombo.frame = opt.frame;
2460 optCombo.subControls = opt.subControls;
2461 optCombo.activeSubControls = opt.activeSubControls;
2462 optCombo.state = opt.state;
2463 if (d->readOnly) {
2464 optCombo.state &= ~QStyle::State_Enabled;
2465 }
2466
2467 QStylePainter p(this);
2468 p.drawComplexControl(QStyle::CC_ComboBox, optCombo);
2469}
2470
2472{
2473 for (int i=0; i<sectionNodes.size(); ++i) {
2474 if (convertToPublic(sectionNodes.at(i).type) == s && index-- == 0) {
2475 return i;
2476 }
2477 }
2478 return NoSectionIndex;
2479}
2480
2482{
2483 return sectionNodes.indexOf(s);
2484}
2485
2503
2509
2517void QDateTimeEdit::initStyleOption(QStyleOptionSpinBox *option) const
2518{
2519 if (!option)
2520 return;
2521
2522 Q_D(const QDateTimeEdit);
2524 if (d->calendarPopupEnabled()) {
2527 if (d->arrowState == QStyle::State_Sunken)
2528 option->state |= QStyle::State_Sunken;
2529 else
2530 option->state &= ~QStyle::State_Sunken;
2531 }
2532}
2533
2535{
2536 Q_Q(QDateTimeEdit);
2537 switch (var.userType()) {
2538 case QMetaType::QDate:
2541 q->setDisplayFormat(defaultDateFormat);
2542 if (sectionNodes.isEmpty()) // ### safeguard for broken locale
2543 q->setDisplayFormat("dd/MM/yyyy"_L1);
2544 break;
2545 case QMetaType::QDateTime:
2546 value = var;
2548 q->setDisplayFormat(defaultDateTimeFormat);
2549 if (sectionNodes.isEmpty()) // ### safeguard for broken locale
2550 q->setDisplayFormat("dd/MM/yyyy hh:mm:ss"_L1);
2551 break;
2552 case QMetaType::QTime:
2555 q->setDisplayFormat(defaultTimeFormat);
2556 if (sectionNodes.isEmpty()) // ### safeguard for broken locale
2557 q->setDisplayFormat("hh:mm:ss"_L1);
2558 break;
2559 default:
2560 Q_ASSERT_X(0, "QDateTimeEditPrivate::init", "Internal error");
2561 break;
2562 }
2563#ifdef QT_KEYPAD_NAVIGATION
2564 if (QApplicationPrivate::keypadNavigationEnabled())
2565 q->setCalendarPopup(true);
2566#endif
2567 q->setInputMethodHints(Qt::ImhPreferNumbers);
2569}
2570
2575
2577{
2578 Q_Q(QDateTimeEdit);
2579
2580 if (arrowState == state)
2581 return;
2582 arrowState = state;
2584 buttonState |= Mouse;
2585 else {
2586 buttonState = 0;
2588 }
2589 q->update();
2590}
2591
2598{
2599 if (!calendarPopupEnabled())
2601
2602 Q_Q(QDateTimeEdit);
2603
2604 QStyleOptionComboBox optCombo;
2605 optCombo.initFrom(q);
2606 optCombo.editable = true;
2607 optCombo.subControls = QStyle::SC_All;
2608 hoverControl = q->style()->hitTestComplexControl(QStyle::CC_ComboBox, &optCombo, pos, q);
2609 return hoverControl;
2610}
2611
2613{
2614 if (!calendarPopupEnabled()) {
2616 return;
2617 }
2618
2619 Q_Q(QDateTimeEdit);
2620
2621 QStyleOptionComboBox optCombo;
2622 optCombo.initFrom(q);
2623 optCombo.editable = true;
2624 optCombo.subControls = QStyle::SC_ComboBoxEditField;
2625 edit->setGeometry(q->style()->subControlRect(QStyle::CC_ComboBox, &optCombo,
2627}
2628
2630{
2631 Q_ASSERT(type == QMetaType::QDateTime);
2632 return QDATETIMEEDIT_DATE_INITIAL.startOfDay(timeZone);
2633}
2634
2636{
2639}
2640
2641
2643{
2644 if (!ke->text().isEmpty() && currentSectionIndex + 1 < sectionNodes.size() && currentSectionIndex >= 0) {
2646 if (ke->text().at(0).isNumber())
2647 return false;
2648 } else if (ke->text().at(0).isLetterOrNumber()) {
2649 return false;
2650 }
2651 return separators.at(currentSectionIndex + 1).contains(ke->text());
2652 }
2653 return false;
2654}
2655
2657{
2658 Q_Q(QDateTimeEdit);
2659 if (!monthCalendar) {
2661 monthCalendar->setObjectName("qt_datetimedit_calendar"_L1);
2662 QObject::connect(monthCalendar, SIGNAL(newDateSelected(QDate)), q, SLOT(setDate(QDate)));
2663 QObject::connect(monthCalendar, SIGNAL(hidingCalendar(QDate)), q, SLOT(setDate(QDate)));
2664 QObject::connect(monthCalendar, SIGNAL(activated(QDate)), q, SLOT(setDate(QDate)));
2667 } else if (cw) {
2669 }
2671}
2672
2674{
2675 Q_Q(QDateTimeEdit);
2676 QPoint pos = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().bottomRight() : q->rect().bottomLeft();
2677 QPoint pos2 = (q->layoutDirection() == Qt::RightToLeft) ? q->rect().topRight() : q->rect().topLeft();
2678 pos = q->mapToGlobal(pos);
2679 pos2 = q->mapToGlobal(pos2);
2682 if (!screen)
2684 const QRect screenRect = screen->availableGeometry();
2685 //handle popup falling "off screen"
2686 if (q->layoutDirection() == Qt::RightToLeft) {
2687 pos.setX(pos.x()-size.width());
2688 pos2.setX(pos2.x()-size.width());
2689 if (pos.x() < screenRect.left())
2690 pos.setX(qMax(pos.x(), screenRect.left()));
2691 else if (pos.x()+size.width() > screenRect.right())
2692 pos.setX(qMax(pos.x()-size.width(), screenRect.right()-size.width()));
2693 } else {
2694 if (pos.x()+size.width() > screenRect.right())
2695 pos.setX(screenRect.right()-size.width());
2696 pos.setX(qMax(pos.x(), screenRect.left()));
2697 }
2698 if (pos.y() + size.height() > screenRect.bottom())
2699 pos.setY(pos2.y() - size.height());
2700 else if (pos.y() < screenRect.top())
2701 pos.setY(screenRect.top());
2702 if (pos.y() < screenRect.top())
2703 pos.setY(screenRect.top());
2704 if (pos.y()+size.height() > screenRect.bottom())
2705 pos.setY(screenRect.bottom()-size.height());
2707}
2708
2713
2715{
2716 Q_Q(QDateTimeEdit);
2717 if (monthCalendar) {
2718 const QSignalBlocker blocker(monthCalendar);
2719 monthCalendar->setDateRange(q->minimumDate(), q->maximumDate());
2720 monthCalendar->setDate(q->date());
2721 }
2722}
2723
2725 : QWidget(parent, Qt::Popup), calendarSystem(ca)
2726{
2728
2729 dateChanged = false;
2730 if (!cw) {
2731 verifyCalendarInstance();
2732 } else {
2734 }
2735}
2736
2737QCalendarWidget *QCalendarPopup::verifyCalendarInstance()
2738{
2739 if (calendar.isNull()) {
2740 QCalendarWidget *cw = new QCalendarWidget(this);
2741 cw->setCalendar(calendarSystem);
2742 cw->setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
2743#ifdef QT_KEYPAD_NAVIGATION
2744 if (QApplicationPrivate::keypadNavigationEnabled())
2745 cw->setHorizontalHeaderFormat(QCalendarWidget::SingleLetterDayNames);
2746#endif
2748 return cw;
2749 } else {
2750 return calendar.data();
2751 }
2752}
2753
2755{
2756 Q_ASSERT(cw);
2757 QVBoxLayout *widgetLayout = qobject_cast<QVBoxLayout*>(layout());
2758 if (!widgetLayout) {
2759 widgetLayout = new QVBoxLayout(this);
2760 widgetLayout->setContentsMargins(QMargins());
2761 widgetLayout->setSpacing(0);
2762 }
2763 delete calendar.data();
2764 calendar = QPointer<QCalendarWidget>(cw);
2765 widgetLayout->addWidget(cw);
2766
2767 connect(cw, SIGNAL(activated(QDate)), this, SLOT(dateSelected(QDate)));
2768 connect(cw, SIGNAL(clicked(QDate)), this, SLOT(dateSelected(QDate)));
2769 connect(cw, SIGNAL(selectionChanged()), this, SLOT(dateSelectionChanged()));
2770
2771 cw->setFocus();
2772}
2773
2774
2776{
2777 oldDate = date;
2778 verifyCalendarInstance()->setSelectedDate(date);
2779}
2780
2782{
2783 QCalendarWidget *cw = verifyCalendarInstance();
2784 cw->setMinimumDate(min);
2785 cw->setMaximumDate(max);
2786}
2787
2789{
2790 QDateTimeEdit *dateTime = qobject_cast<QDateTimeEdit *>(parentWidget());
2791 if (dateTime) {
2794 QRect arrowRect = dateTime->style()->subControlRect(QStyle::CC_ComboBox, &opt,
2796 arrowRect.moveTo(dateTime->mapToGlobal(arrowRect .topLeft()));
2797 if (arrowRect.contains(event->globalPosition().toPoint()) || rect().contains(event->position().toPoint()))
2799 }
2801}
2802
2807
2809{
2810#if QT_CONFIG(shortcut)
2811 if (event->type() == QEvent::KeyPress) {
2812 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
2813 if (keyEvent->matches(QKeySequence::Cancel))
2814 dateChanged = false;
2815 }
2816#endif
2817 return QWidget::event(event);
2818}
2819
2820void QCalendarPopup::dateSelectionChanged()
2821{
2822 dateChanged = true;
2823 emit newDateSelected(verifyCalendarInstance()->selectedDate());
2824}
2825void QCalendarPopup::dateSelected(QDate date)
2826{
2827 dateChanged = true;
2829 close();
2830}
2831
2833{
2834 emit resetButton();
2835 if (!dateChanged)
2836 emit hidingCalendar(oldDate);
2837}
2838
2840#include "moc_qdatetimeedit.cpp"
2841#include "moc_qdatetimeedit_p.cpp"
virtual QStyle::SubControl newHoverControl(const QPoint &pos)
virtual void setRange(const QVariant &min, const QVariant &max)
virtual void interpret(EmitPolicy ep)
QStyle::SubControl hoverControl
virtual void updateEditFieldGeometry()
virtual QVariant bound(const QVariant &val, const QVariant &old=QVariant(), int steps=0) const
virtual void clearCache() const
QValidator::State cachedState
void setValue(const QVariant &val, EmitPolicy ep, bool updateEdit=true)
QAbstractSpinBox::CorrectionMode correctionMode
The QAbstractSpinBox class provides a spinbox and a line edit to display values.
void selectAll()
Selects all the text in the spinbox except the prefix and suffix.
void editingFinished()
This signal is emitted editing is finished.
void focusInEvent(QFocusEvent *event) override
\reimp
QString text
the spin box's text, including any prefix and suffix
void paintEvent(QPaintEvent *event) override
\reimp
void mousePressEvent(QMouseEvent *event) override
\reimp
virtual void initStyleOption(QStyleOptionSpinBox *option) const
Initialize option with the values from this QSpinBox.
bool event(QEvent *event) override
\reimp
void keyPressEvent(QKeyEvent *event) override
\reimp
void activated(QDate date)
void mousePressEvent(QMouseEvent *e) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
void mouseReleaseEvent(QMouseEvent *) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
void hidingCalendar(QDate oldDate)
void setCalendarWidget(QCalendarWidget *cw)
void setDate(QDate date)
void hideEvent(QHideEvent *) override
This event handler can be reimplemented in a subclass to receive widget hide events.
void setDateRange(QDate min, QDate max)
bool event(QEvent *e) override
This virtual function receives events to an object and should return true if the event e was recogniz...
void newDateSelected(QDate newDate)
QCalendarPopup(QWidget *parent=nullptr, QCalendarWidget *cw=nullptr, QCalendar ca=QCalendar())
void resetButton()
QCalendarWidget * calendarWidget() const
The QCalendarWidget class provides a monthly based calendar widget allowing the user to select a date...
void setSelectedDate(QDate date)
The QCalendar class describes calendar systems.
Definition qcalendar.h:53
\inmodule QtCore
QDateEdit(QWidget *parent=nullptr)
Constructs an empty date editor with a parent.
void userDateChanged(QDate date)
This signal only exists to fully implement the date Q_PROPERTY on the class.
~QDateEdit()
Destructor.
QDateTime getMaximum() const override
bool calendarPopupEnabled() const
void clearSection(int index)
int closestSection(int index, bool forward) const
QVariant valueFromText(const QString &f) const override
void emitSignals(EmitPolicy ep, const QVariant &old) override
QString textFromValue(const QVariant &f) const override
QDateTime stepBy(int index, int steps, bool test=false) const
QDateTimeEditPrivate(const QTimeZone &zone=QTimeZone::LocalTime)
int sectionAt(int pos) const
void clearCache() const override
bool isSeparatorKey(const QKeyEvent *k) const
void updateEditFieldGeometry() override
QCalendarPopup * monthCalendar
QLocale locale() const override
void editorCursorPositionChanged(int oldpos, int newpos) override
QDateTime convertTimeZone(const QDateTime &datetime)
void setSelected(int index, bool forward=false)
void updateEdit() override
static QDateTimeEdit::Sections convertSections(QDateTimeParser::Sections s)
static QDateTimeEdit::Section convertToPublic(QDateTimeParser::Section s)
QDateTime getMinimum() const override
void setRange(const QVariant &min, const QVariant &max) override
QStyle::SubControl newHoverControl(const QPoint &pos) override
QDateTime validateAndInterpret(QString &input, int &, QValidator::State &state, bool fixup=false) const
void updateCache(const QVariant &val, const QString &str) const
void initCalendarPopup(QCalendarWidget *cw=nullptr)
QDateTime dateTimeValue(QDate date, QTime time) const
QDateTimeEdit::Sections sections
int absoluteIndex(QDateTimeEdit::Section s, int index) const
QStyle::StateFlag arrowState
QVariant getZeroVariant() const override
int nextPrevSection(int index, bool forward) const
void interpret(EmitPolicy ep) override
void updateArrow(QStyle::StateFlag state)
QString displayText() const override
The QDateTimeEdit class provides a widget for editing dates and times.
void setCurrentSectionIndex(int index)
void clearMaximumDateTime()
void setTimeRange(QTime min, QTime max)
Set the range of allowed times for the date time edit.
void setMinimumDate(QDate min)
QTime maximumTime
The maximum time of the date time edit.
void setDateTimeRange(const QDateTime &min, const QDateTime &max)
Set the range of allowed date-times for the date time edit.
void setMaximumTime(QTime max)
QString displayFormat
The format used to display the time/date of the date time edit.
int sectionCount
The number of sections displayed. If the format is 'yyyy/yy/yyyy', sectionCount returns 3.
void keyPressEvent(QKeyEvent *event) override
\reimp
Sections displayedSections
The currently displayed fields of the date time edit.
bool event(QEvent *event) override
\reimp
bool focusNextPrevChild(bool next) override
\reimp
QValidator::State validate(QString &input, int &pos) const override
\reimp
QCalendar calendar() const
void setDate(QDate date)
QCalendarWidget * calendarWidget() const
Returns the calendar widget for the editor if calendarPopup is set to true and (sections() & DateSect...
void focusInEvent(QFocusEvent *event) override
\reimp
QDateTime maximumDateTime
The maximum datetime of the date time edit.
QTime minimumTime
The minimum time of the date time edit.
void setCalendarPopup(bool enable)
void setMaximumDate(QDate max)
void setTimeZone(const QTimeZone &zone)
void clear() override
\reimp
void setDateRange(QDate min, QDate max)
Set the range of allowed dates for the date time edit.
void setDisplayFormat(const QString &format)
void setSelectedSection(Section section)
virtual QString textFromDateTime(const QDateTime &dt) const
This virtual function is used by the date time edit whenever it needs to display dateTime.
void mousePressEvent(QMouseEvent *event) override
\reimp
virtual QDateTime dateTimeFromText(const QString &text) const
Returns an appropriate datetime for the given text.
void initStyleOption(QStyleOptionSpinBox *option) const override
Initialize option with the values from this QDataTimeEdit.
void setCurrentSection(Section section)
int currentSectionIndex
The current section index of the spinbox.
QString sectionText(Section section) const
Returns the text from the given section.
QDateTime minimumDateTime
The minimum datetime of the date time edit.
Section
\value NoSection \value AmPmSection \value MSecSection \value SecondSection \value MinuteSection \val...
Section currentSection
The current section of the spinbox.
void dateChanged(QDate date)
This signal is emitted whenever the date is changed.
void setCalendar(QCalendar calendar)
void setTime(QTime time)
QDateTimeEdit(QWidget *parent=nullptr)
Constructs an empty date time editor with a parent.
QTime time
The QTime that is set in the widget.
QTimeZone timeZone
The current timezone used by the datetime editing widget.
void setMinimumDateTime(const QDateTime &dt)
bool calendarPopup
The current calendar pop-up show mode.
void setDateTime(const QDateTime &dateTime)
void setMaximumDateTime(const QDateTime &dt)
void setMinimumTime(QTime min)
StepEnabled stepEnabled() const override
\reimp
~QDateTimeEdit()
Destructor.
Section sectionAt(int index) const
void setCalendarWidget(QCalendarWidget *calendarWidget)
void fixup(QString &input) const override
\reimp
void paintEvent(QPaintEvent *event) override
\reimp
QDate minimumDate
The minimum date of the date time edit.
void clearMinimumDateTime()
void timeChanged(QTime time)
This signal is emitted whenever the time is changed.
void stepBy(int steps) override
\reimp
QDateTime dateTime
The QDateTime that is set in the QDateTimeEdit.
QDate maximumDate
The maximum date of the date time edit.
QDate date
The QDate that is set in the widget.
QSize sizeHint() const override
\reimp
int absoluteMin(int index) const
int sectionSize(int index) const
int absoluteMax(int index, const QDateTime &value=QDateTime()) const
FieldInfo fieldInfo(int index) const
virtual QDateTime getMaximum() const
int getDigit(const QDateTime &dt, int index) const
StateNode parse(const QString &input, int position, const QDateTime &defaultValue, bool fixup) const
virtual QDateTime getMinimum() const
QList< SectionNode > sectionNodes
const SectionNode & sectionNode(int index) const
bool setDigit(QDateTime &t, int index, int newval) const
int sectionPos(int index) const
\inmodule QtCore\reentrant
Definition qdatetime.h:283
static QDateTime fromMSecsSinceEpoch(qint64 msecs, const QTimeZone &timeZone)
bool isNull() const
Returns true if both the date and the time are null; otherwise returns false.
QDateTime toTimeZone(const QTimeZone &toZone) const
bool isValid() const
Returns true if this datetime represents a definite moment, otherwise false.
QTimeZone timeRepresentation() const
QDate date() const
Returns the date part of the datetime.
\inmodule QtCore \reentrant
Definition qdatetime.h:29
constexpr bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition qdatetime.h:71
QDateTime endOfDay(const QTimeZone &zone) const
QDateTime startOfDay(const QTimeZone &zone) const
\inmodule QtCore
Definition qcoreevent.h:45
@ ApplicationLayoutDirectionChange
Definition qcoreevent.h:92
@ StyleChange
Definition qcoreevent.h:136
@ LocaleChange
Definition qcoreevent.h:122
@ KeyPress
Definition qcoreevent.h:64
@ MacSizeChange
Definition qcoreevent.h:217
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
\reentrant \inmodule QtGui
QScreen * primaryScreen
the primary (or default) screen of the application.
static QScreen * screenAt(const QPoint &point)
Returns the screen at point, or \nullptr if outside of any screen.
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition qevent.h:586
The QKeyEvent class describes a key event.
Definition qevent.h:424
int cursorPosition
The current cursor position for this line edit.
Definition qlineedit.h:37
void selectAll()
Selects all the text (highlights it) and moves the cursor to the end.
bool hasSelectedText
Whether there is any text selected.
Definition qlineedit.h:40
int selectionStart() const
Returns the index of the first selected character in the line edit (or -1 if no text is selected).
QString selectedText
The selected text.
Definition qlineedit.h:41
void setCursorPosition(int)
void setText(const QString &)
void setSelection(int, int)
Selects text from position start and for length characters.
QString text
The line edit's text.
Definition qlineedit.h:32
QString dateTimeFormat(FormatType format=LongFormat) const
Definition qlocale.cpp:2396
QString dateFormat(FormatType format=LongFormat) const
Definition qlocale.cpp:2334
@ ShortFormat
Definition qlocale.h:875
QString timeFormat(FormatType format=LongFormat) const
Definition qlocale.cpp:2365
QString toString(qlonglong i) const
Returns a localized string representation of i.
Definition qlocale.cpp:2052
\inmodule QtCore
Definition qmargins.h:24
\inmodule QtCore
Definition qmetatype.h:341
Type
\macro Q_DECLARE_OPAQUE_POINTER(PointerType)
Definition qmetatype.h:345
\inmodule QtGui
Definition qevent.h:196
uint unused
Definition qobject.h:88
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
Definition qobject.h:127
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
\inmodule QtCore\reentrant
Definition qpoint.h:25
T * data() const noexcept
Definition qpointer.h:73
bool isNull() const noexcept
Definition qpointer.h:84
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:182
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:176
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:173
constexpr void setX(int x) noexcept
Sets the left edge of the rectangle to the given x coordinate.
Definition qrect.h:215
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:179
The QScreen class is used to query screen properties. \inmodule QtGui.
Definition qscreen.h:32
QRect availableGeometry
the screen's available geometry in pixels
Definition qscreen.h:46
Exception-safe wrapper around QObject::blockSignals().
Definition qobject.h:483
\inmodule QtCore
Definition qsize.h:25
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString left(qsizetype n) const &
Definition qstring.h:363
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1252
qsizetype size() const noexcept
Returns the number of characters in this string.
Definition qstring.h:186
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1226
\variable QStyleOptionToolButton::features
QStyle::State state
void initFrom(const QWidget *w)
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget.
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
StateFlag
This enum describes flags that are used when drawing primitive elements.
Definition qstyle.h:65
@ State_Sunken
Definition qstyle.h:69
@ State_None
Definition qstyle.h:66
@ CT_SpinBox
Definition qstyle.h:562
@ CT_ComboBox
Definition qstyle.h:551
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=nullptr) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
@ CC_ComboBox
Definition qstyle.h:333
@ SE_DateTimeEditLayoutItem
Definition qstyle.h:291
SubControl
This enum describes the available sub controls.
Definition qstyle.h:347
@ SC_ComboBoxFrame
Definition qstyle.h:364
@ SC_All
Definition qstyle.h:400
@ SC_ComboBoxEditField
Definition qstyle.h:365
@ SC_ComboBoxArrow
Definition qstyle.h:366
QTimeEdit(QWidget *parent=nullptr)
Constructs an empty time editor with a parent.
~QTimeEdit()
Destructor.
void userTimeChanged(QTime time)
This signal only exists to fully implement the time Q_PROPERTY on the class.
\inmodule QtCore
Definition qtimezone.h:26
constexpr Qt::TimeSpec timeSpec() const noexcept
Definition qtimezone.h:136
\inmodule QtCore \reentrant
Definition qdatetime.h:215
int hour() const
Returns the hour part (0 to 23) of the time.
int minute() const
Returns the minute part (0 to 59) of the time.
bool isValid() const
Returns true if the time is valid; otherwise returns false.
The QVBoxLayout class lines up widgets vertically.
Definition qboxlayout.h:91
State
This enum type defines the states in which a validated string can exist.
Definition qvalidator.h:30
\inmodule QtCore
Definition qvariant.h:65
void clear()
Convert this variant to type QMetaType::UnknownType and free up any resources used.
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has userType() \l QMetaType::QDateTime,...
int userType() const
Definition qvariant.h:339
QTime toTime() const
Returns the variant as a QTime if the variant has userType() \l QMetaType::QTime, \l QMetaType::QDate...
QDate toDate() const
Returns the variant as a QDate if the variant has userType() \l QMetaType::QDate, \l QMetaType::QDate...
void setLayoutItemMargins(int left, int top, int right, int bottom)
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
void setGeometry(int x, int y, int w, int h)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:886
QLayout * layout() const
Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is inst...
virtual void mousePressEvent(QMouseEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition qwidget.cpp:9483
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
bool close()
Closes this widget.
Definition qwidget.cpp:8562
void move(int x, int y)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qwidget.h:880
QFontMetrics fontMetrics() const
Returns the font metrics for the widget's current font.
Definition qwidget.h:847
QLocale locale
the widget's locale
Definition qwidget.h:176
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab,...
Definition qwidget.cpp:6777
QRect rect
the internal geometry of the widget excluding any window frame
Definition qwidget.h:116
void ensurePolished() const
Ensures that the widget and its children have been polished by QStyle (i.e., have a proper font and p...
void update()
Updates the widget unless updates are disabled or the widget is hidden.
QSize sizeHint
the recommended size for the widget
Definition qwidget.h:148
bool isRightToLeft() const
Definition qwidget.h:419
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8866
QStyle * style() const
Definition qwidget.cpp:2600
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
QString str
[2]
QString text
QDate date
[1]
QCursor cursor
QStyleOptionButton opt
else opt state
[0]
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
Definition qcompare.h:63
@ WA_WindowPropagation
Definition qnamespace.h:349
@ WA_NoMouseReplay
Definition qnamespace.h:320
@ WA_MacShowFocusRect
Definition qnamespace.h:359
@ RightToLeft
@ ImhPreferNumbers
@ Key_Tab
Definition qnamespace.h:664
@ Key_Select
@ Key_Return
Definition qnamespace.h:667
@ Key_Right
Definition qnamespace.h:679
@ Key_Enter
Definition qnamespace.h:668
@ Key_Backtab
Definition qnamespace.h:665
@ Key_Left
Definition qnamespace.h:677
@ Key_NumberSign
Definition qnamespace.h:517
@ UTC
@ LocalTime
@ ShiftModifier
@ ControlModifier
@ KeypadModifier
@ PopupFocusReason
@ BacktabFocusReason
@ MouseFocusReason
@ ActiveWindowFocusReason
@ TabFocusReason
@ ShortcutFocusReason
@ EmitIfChanged
@ NeverEmit
@ AlwaysEmit
static jboolean copy(JNIEnv *, jobject)
#define Q_FALLTHROUGH()
#define Q_UNLIKELY(x)
#define QDTEDEBUG
#define QDATETIMEEDIT_COMPAT_DATE_MIN
#define QDATETIMEEDIT_DATE_MIN
#define QDATETIMEEDIT_DATE_MAX
#define QDATETIMEEDIT_DATE_INITIAL
#define QDATETIMEEDIT_TIME_MIN
#define QDATETIMEEDIT_TIME_MAX
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qWarning
Definition qlogging.h:166
return ret
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qBound(const T &min, const T &val, const T &max)
Definition qminmax.h:44
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
#define SLOT(a)
Definition qobjectdefs.h:52
#define SIGNAL(a)
Definition qobjectdefs.h:53
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLsizei const GLfloat * v
[13]
const GLfloat * m
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLfloat GLfloat f
GLenum type
GLboolean enable
GLint first
GLint GLsizei GLsizei GLenum format
GLfloat GLfloat GLfloat GLfloat h
struct _cl_event * event
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
GLuint GLfloat * val
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLenum GLenum GLsizei void GLsizei void void * span
GLfloat GLfloat p
[1]
GLuint GLenum option
GLenum GLenum GLenum input
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
static const struct TessellationWindingOrderTab cw[]
SSL_CTX int void * arg
#define qPrintable(string)
Definition qstring.h:1531
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
QScreen * screen
[1]
Definition main.cpp:29
#define emit
static double UTC(double t, double localTZA)
static double LocalTime(double t, double localTZA)
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QDateTime dateTime
[12]
ba fill(true)
selection select(topLeft, bottomRight)
QCalendarWidget * calendar
[0]
static QString name(Section s)