Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qabstractspinbox.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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 <qplatformdefs.h>
5#include <private/qabstractspinbox_p.h>
6#include <private/qapplication_p.h>
7#if QT_CONFIG(datetimeparser)
8#include <private/qdatetimeparser_p.h>
9#endif
10#include <private/qlineedit_p.h>
11#include <qabstractspinbox.h>
12
13#include <qapplication.h>
14#include <qstylehints.h>
15#include <qclipboard.h>
16#include <qdatetime.h>
17#include <qevent.h>
18#if QT_CONFIG(menu)
19#include <qmenu.h>
20#endif
21#include <qpainter.h>
22#include <qpalette.h>
23#include <qstylepainter.h>
24#include <qdebug.h>
25#if QT_CONFIG(accessibility)
26# include <qaccessible.h>
27#endif
28
29
30//#define QABSTRACTSPINBOX_QSBDEBUG
31#ifdef QABSTRACTSPINBOX_QSBDEBUG
32# define QASBDEBUG qDebug
33#else
34# define QASBDEBUG if (false) qDebug
35#endif
36
38
39using namespace Qt::StringLiterals;
40
117{
118 Q_D(QAbstractSpinBox);
119 d->init();
120}
121
126 : QWidget(dd, parent, { })
127{
128 Q_D(QAbstractSpinBox);
129 d->init();
130}
131
137{
138}
139
171{
172 Q_D(const QAbstractSpinBox);
173 return d->buttonSymbols;
174}
175
177{
178 Q_D(QAbstractSpinBox);
179 if (d->buttonSymbols != buttonSymbols) {
180 d->buttonSymbols = buttonSymbols;
181 d->updateEditFieldGeometry();
183 update();
184 }
185}
186
196{
197 return lineEdit()->displayText();
198}
199
200
235{
236 Q_D(const QAbstractSpinBox);
237 return d->specialValueText;
238}
239
241{
242 Q_D(QAbstractSpinBox);
243
244 d->specialValueText = specialValueText;
245 d->cachedSizeHint = QSize(); // minimumSizeHint doesn't care about specialValueText
246 d->clearCache();
247 d->updateEdit();
248}
249
265{
266 Q_D(const QAbstractSpinBox);
267 return d->wrapping;
268}
269
271{
272 Q_D(QAbstractSpinBox);
273 d->wrapping = wrapping;
274}
275
276
292{
293 Q_D(const QAbstractSpinBox);
294 return d->readOnly;
295}
296
298{
299 Q_D(QAbstractSpinBox);
300 d->readOnly = enable;
301 d->edit->setReadOnly(enable);
304 update();
305}
306
328{
329 Q_D(const QAbstractSpinBox);
330 return d->keyboardTracking;
331}
332
334{
335 Q_D(QAbstractSpinBox);
336 d->keyboardTracking = enable;
337}
338
348{
349 Q_D(const QAbstractSpinBox);
350 return d->frame;
351}
352
353
355{
356 Q_D(QAbstractSpinBox);
357 d->frame = enable;
358 update();
359 d->updateEditFieldGeometry();
360}
361
373{
374 Q_D(QAbstractSpinBox);
375 d->accelerate = accelerate;
376
377}
379{
380 Q_D(const QAbstractSpinBox);
381 return d->accelerate;
382}
383
393{
394 Q_D(const QAbstractSpinBox);
395 return d->showGroupSeparator;
396}
397
399{
400 Q_D(QAbstractSpinBox);
401 if (d->showGroupSeparator == shown)
402 return;
403 d->showGroupSeparator = shown;
404 d->setValue(d->value, EmitIfChanged);
406}
407
434{
435 Q_D(QAbstractSpinBox);
436 d->correctionMode = correctionMode;
437
438}
440{
441 Q_D(const QAbstractSpinBox);
442 return d->correctionMode;
443}
444
445
455{
456 Q_D(const QAbstractSpinBox);
457 return d->edit->hasAcceptableInput();
458}
459
474Qt::Alignment QAbstractSpinBox::alignment() const
475{
476 Q_D(const QAbstractSpinBox);
477
478 return (Qt::Alignment)d->edit->alignment();
479}
480
481void QAbstractSpinBox::setAlignment(Qt::Alignment flag)
482{
483 Q_D(QAbstractSpinBox);
484
485 d->edit->setAlignment(flag);
486}
487
493{
494 Q_D(QAbstractSpinBox);
495
496
497 if (!d->specialValue()) {
498 const int tmp = d->edit->displayText().size() - d->suffix.size();
499 d->edit->setSelection(tmp, -(tmp - d->prefix.size()));
500 } else {
501 d->edit->selectAll();
502 }
503}
504
510{
511 Q_D(QAbstractSpinBox);
512
513 d->edit->setText(d->prefix + d->suffix);
514 d->edit->setCursorPosition(d->prefix.size());
515 d->cleared = true;
516}
517
536QAbstractSpinBox::StepEnabled QAbstractSpinBox::stepEnabled() const
537{
538 Q_D(const QAbstractSpinBox);
539 if (d->readOnly || d->type == QMetaType::UnknownType)
540 return StepNone;
541 if (d->wrapping)
542 return StepEnabled(StepUpEnabled | StepDownEnabled);
543 StepEnabled ret = StepNone;
544 if (QAbstractSpinBoxPrivate::variantCompare(d->value, d->maximum) < 0) {
546 }
547 if (QAbstractSpinBoxPrivate::variantCompare(d->value, d->minimum) > 0) {
549 }
550 return ret;
551}
552
560QValidator::State QAbstractSpinBox::validate(QString & /* input */, int & /* pos */) const
561{
563}
564
572void QAbstractSpinBox::fixup(QString & /* input */) const
573{
574}
575
583{
584 stepBy(1);
585}
586
594{
595 stepBy(-1);
596}
612{
613 Q_D(QAbstractSpinBox);
614
615 const QVariant old = d->value;
616 QString tmp = d->edit->displayText();
617 int cursorPos = d->edit->cursorPosition();
618 bool dontstep = false;
620 if (d->pendingEmit) {
621 dontstep = validate(tmp, cursorPos) != QValidator::Acceptable;
622 d->cleared = false;
623 d->interpret(NeverEmit);
624 if (d->value != old)
625 e = AlwaysEmit;
626 }
627 if (!dontstep) {
628 QVariant singleStep;
629 switch (d->stepType) {
631 singleStep = d->calculateAdaptiveDecimalStep(steps);
632 break;
633 default:
634 singleStep = d->singleStep;
635 }
636 d->setValue(d->bound(d->value + (singleStep * steps), old, steps), e);
637 } else if (e == AlwaysEmit) {
638 d->emitSignals(e, old);
639 }
640 if (style()->styleHint(QStyle::SH_SpinBox_SelectOnStep, nullptr, this, nullptr))
641 selectAll();
642}
643
649{
650 Q_D(const QAbstractSpinBox);
651
652 return d->edit;
653}
654
655
669{
670 Q_D(QAbstractSpinBox);
671
672 if (!lineEdit) {
674 return;
675 }
676
677 if (lineEdit == d->edit)
678 return;
679
680 delete d->edit;
681 d->edit = lineEdit;
682 setProperty("_q_spinbox_lineedit", QVariant::fromValue<QWidget *>(d->edit));
683 if (!d->edit->validator())
684 d->edit->setValidator(d->validator);
685
686 if (d->edit->parent() != this)
687 d->edit->setParent(this);
688
689 d->edit->setFrame(!style()->styleHint(QStyle::SH_SpinBox_ButtonsInsideFrame, nullptr, this));
690 d->edit->setFocusProxy(this);
691 d->edit->setAcceptDrops(false);
692
693 if (d->type != QMetaType::UnknownType) {
695 this, SLOT(_q_editorTextChanged(QString)));
696 connect(d->edit, SIGNAL(cursorPositionChanged(int,int)),
697 this, SLOT(_q_editorCursorPositionChanged(int,int)));
698 connect(d->edit, SIGNAL(cursorPositionChanged(int,int)),
699 this, SLOT(updateMicroFocus()));
700 connect(d->edit->d_func()->control, SIGNAL(updateMicroFocus()),
701 this, SLOT(updateMicroFocus()));
702 }
703 d->updateEditFieldGeometry();
704 d->edit->setContextMenuPolicy(Qt::NoContextMenu);
705 d->edit->d_func()->control->setAccessibleObject(this);
706
707 if (isVisible())
708 d->edit->show();
709 if (isVisible())
710 d->updateEdit();
711}
712
713
720{
721 Q_D(QAbstractSpinBox);
722 d->interpret(EmitIfChanged);
723}
724
725/*
726 Reimplemented in 4.6, so be careful.
727 */
732{
733 Q_D(const QAbstractSpinBox);
734 const QVariant lineEditValue = d->edit->inputMethodQuery(query);
735 switch (query) {
736 case Qt::ImHints:
737 if (const int hints = inputMethodHints())
738 return QVariant(hints | lineEditValue.toInt());
739 break;
740 default:
741 break;
742 }
743 return lineEditValue;
744}
745
751{
752 Q_D(QAbstractSpinBox);
753 switch (event->type()) {
756 d->cachedSizeHint = d->cachedMinimumSizeHint = QSize();
757 break;
760 d->updateEditFieldGeometry();
761 break;
765 d->updateHoverControl(static_cast<const QHoverEvent *>(event)->position().toPoint());
766 break;
768 if (d->edit->event(event))
769 return true;
770 break;
771#ifdef QT_KEYPAD_NAVIGATION
772 case QEvent::EnterEditFocus:
773 case QEvent::LeaveEditFocus:
774 if (QApplicationPrivate::keypadNavigationEnabled()) {
775 const bool b = d->edit->event(event);
776 d->edit->setSelection(d->edit->displayText().size() - d->suffix.size(),0);
777 if (event->type() == QEvent::LeaveEditFocus)
779 if (b)
780 return true;
781 }
782 break;
783#endif
785 return d->edit->event(event);
786 default:
787 break;
788 }
789 return QWidget::event(event);
790}
791
797{
798 Q_D(QAbstractSpinBox);
799 d->reset();
800
801 if (d->ignoreUpdateEdit) {
802 d->ignoreUpdateEdit = false;
803 } else {
804 d->updateEdit();
805 }
806}
807
813{
814 Q_D(QAbstractSpinBox);
815
816 switch (event->type()) {
818 d->spinClickTimerInterval = style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, nullptr, this);
819 d->spinClickThresholdTimerInterval =
821 if (d->edit)
822 d->edit->setFrame(!style()->styleHint(QStyle::SH_SpinBox_ButtonsInsideFrame, nullptr, this));
823 d->stepModifier = static_cast<Qt::KeyboardModifier>(style()->styleHint(QStyle::SH_SpinBox_StepModifier, nullptr, this));
824 d->reset();
825 d->updateEditFieldGeometry();
826 break;
828 d->updateEdit();
829 break;
831 if (!isEnabled()) {
832 d->reset();
833 }
834 break;
836 if (!isActiveWindow()){
837 d->reset();
838 if (d->pendingEmit) // pendingEmit can be true even if it hasn't changed.
839 d->interpret(EmitIfChanged); // E.g. 10 to 10.0
840 }
841 break;
842 default:
843 break;
844 }
846}
847
853{
854 Q_D(QAbstractSpinBox);
856
857 d->updateEditFieldGeometry();
858 update();
859}
860
866{
867 Q_D(const QAbstractSpinBox);
868 if (d->cachedSizeHint.isEmpty()) {
870
871 const QFontMetrics fm(fontMetrics());
872 int h = d->edit->sizeHint().height();
873 int w = 0;
874 QString s;
875 QString fixedContent = d->prefix + d->suffix + u' ';
876 s = d->textFromValue(d->minimum);
877 s.truncate(18);
878 s += fixedContent;
879 w = qMax(w, fm.horizontalAdvance(s));
880 s = d->textFromValue(d->maximum);
881 s.truncate(18);
882 s += fixedContent;
883 w = qMax(w, fm.horizontalAdvance(s));
884
885 if (d->specialValueText.size()) {
886 s = d->specialValueText;
887 w = qMax(w, fm.horizontalAdvance(s));
888 }
889 w += 2; // cursor blinking space
890
891 QStyleOptionSpinBox opt;
893 QSize hint(w, h);
894 d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this);
895 }
896 return d->cachedSizeHint;
897}
898
904{
905 Q_D(const QAbstractSpinBox);
906 if (d->cachedMinimumSizeHint.isEmpty()) {
907 //Use the prefix and range to calculate the minimumSizeHint
909
910 const QFontMetrics fm(fontMetrics());
911 int h = d->edit->minimumSizeHint().height();
912 int w = 0;
913
914 QString s;
915 QString fixedContent = d->prefix + u' ';
916 s = d->textFromValue(d->minimum);
917 s.truncate(18);
918 s += fixedContent;
919 w = qMax(w, fm.horizontalAdvance(s));
920 s = d->textFromValue(d->maximum);
921 s.truncate(18);
922 s += fixedContent;
923 w = qMax(w, fm.horizontalAdvance(s));
924
925 if (d->specialValueText.size()) {
926 s = d->specialValueText;
927 w = qMax(w, fm.horizontalAdvance(s));
928 }
929 w += 2; // cursor blinking space
930
931 QStyleOptionSpinBox opt;
933 QSize hint(w, h);
934
935 d->cachedMinimumSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this);
936 }
937 return d->cachedMinimumSizeHint;
938}
939
945{
946 QStyleOptionSpinBox opt;
948 QStylePainter p(this);
949 p.drawComplexControl(QStyle::CC_SpinBox, opt);
950}
951
977{
978 Q_D(QAbstractSpinBox);
979
980 d->keyboardModifiers = event->modifiers();
981
982 if (!event->text().isEmpty() && d->edit->cursorPosition() < d->prefix.size())
983 d->edit->setCursorPosition(d->prefix.size());
984
985 int steps = 1;
986 bool isPgUpOrDown = false;
987 switch (event->key()) {
988 case Qt::Key_PageUp:
989 case Qt::Key_PageDown:
990 steps *= 10;
991 isPgUpOrDown = true;
993 case Qt::Key_Up:
994 case Qt::Key_Down: {
995#ifdef QT_KEYPAD_NAVIGATION
996 if (QApplicationPrivate::keypadNavigationEnabled()) {
997 // Reserve up/down for nav - use left/right for edit.
998 if (!hasEditFocus() && (event->key() == Qt::Key_Up
999 || event->key() == Qt::Key_Down)) {
1000 event->ignore();
1001 return;
1002 }
1003 }
1004#endif
1005 event->accept();
1006 const bool up = (event->key() == Qt::Key_PageUp || event->key() == Qt::Key_Up);
1007 if (!(stepEnabled() & (up ? StepUpEnabled : StepDownEnabled)))
1008 return;
1009 if (!isPgUpOrDown && (event->modifiers() & d->stepModifier))
1010 steps *= 10;
1011 if (!up)
1012 steps *= -1;
1013 if (style()->styleHint(QStyle::SH_SpinBox_AnimateButton, nullptr, this)) {
1014 d->buttonState = (Keyboard | (up ? Up : Down));
1015 }
1016 if (d->spinClickTimerId == -1)
1017 stepBy(steps);
1018 if (event->isAutoRepeat() && !isPgUpOrDown) {
1019 if (d->spinClickThresholdTimerId == -1 && d->spinClickTimerId == -1) {
1020 d->updateState(up, true);
1021 }
1022 }
1023#if QT_CONFIG(accessibility)
1024 QAccessibleValueChangeEvent event(this, d->value);
1025 QAccessible::updateAccessibility(&event);
1026#endif
1027 return;
1028 }
1029#ifdef QT_KEYPAD_NAVIGATION
1030 case Qt::Key_Left:
1031 case Qt::Key_Right:
1032 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
1033 event->ignore();
1034 return;
1035 }
1036 break;
1037 case Qt::Key_Back:
1038 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
1039 event->ignore();
1040 return;
1041 }
1042 break;
1043#endif
1044 case Qt::Key_Enter:
1045 case Qt::Key_Return:
1046 d->edit->d_func()->control->clearUndo();
1047 d->interpret(d->keyboardTracking ? AlwaysEmit : EmitIfChanged);
1048 selectAll();
1049 event->ignore();
1051 emit d->edit->returnPressed();
1052 return;
1053
1054#ifdef QT_KEYPAD_NAVIGATION
1055 case Qt::Key_Select:
1056 if (QApplicationPrivate::keypadNavigationEnabled()) {
1057 // Toggles between left/right moving cursor and inc/dec.
1058 setEditFocus(!hasEditFocus());
1059 }
1060 return;
1061#endif
1062
1063 case Qt::Key_U:
1064 if (event->modifiers() & Qt::ControlModifier
1065 && QGuiApplication::platformName() == "xcb"_L1) { // only X11
1066 event->accept();
1067 if (!isReadOnly())
1068 clear();
1069 return;
1070 }
1071 break;
1072
1073 case Qt::Key_End:
1074 case Qt::Key_Home:
1075 if (event->modifiers() & Qt::ShiftModifier) {
1076 int currentPos = d->edit->cursorPosition();
1077 const QString text = d->edit->displayText();
1078 if (event->key() == Qt::Key_End) {
1079 if ((currentPos == 0 && !d->prefix.isEmpty()) || text.size() - d->suffix.size() <= currentPos) {
1080 break; // let lineedit handle this
1081 } else {
1082 d->edit->setSelection(currentPos, text.size() - d->suffix.size() - currentPos);
1083 }
1084 } else {
1085 if ((currentPos == text.size() && !d->suffix.isEmpty()) || currentPos <= d->prefix.size()) {
1086 break; // let lineedit handle this
1087 } else {
1088 d->edit->setSelection(currentPos, d->prefix.size() - currentPos);
1089 }
1090 }
1091 event->accept();
1092 return;
1093 }
1094 break;
1095
1096 default:
1097#ifndef QT_NO_SHORTCUT
1099 selectAll();
1100 event->accept();
1101 return;
1102 }
1103#endif
1104 break;
1105 }
1106
1107 d->edit->event(event);
1108 if (!d->edit->text().isEmpty())
1109 d->cleared = false;
1110 if (!isVisible())
1111 d->ignoreUpdateEdit = true;
1112}
1113
1119{
1120 Q_D(QAbstractSpinBox);
1121
1122 d->keyboardModifiers = event->modifiers();
1123 if (d->buttonState & Keyboard && !event->isAutoRepeat()) {
1124 d->reset();
1125 } else {
1126 d->edit->event(event);
1127 }
1128}
1129
1134#if QT_CONFIG(wheelevent)
1135void QAbstractSpinBox::wheelEvent(QWheelEvent *event)
1136{
1137 Q_D(QAbstractSpinBox);
1138#ifdef Q_OS_MACOS
1139 // If the event comes from a real mouse wheel, rather than a track pad
1140 // (Qt::MouseEventSynthesizedBySystem), the shift modifier changes the
1141 // scroll orientation to horizontal.
1142 // Convert horizontal events back to vertical whilst shift is held.
1143 if ((event->modifiers() & Qt::ShiftModifier)
1144 && event->source() == Qt::MouseEventNotSynthesized) {
1145 d->wheelDeltaRemainder += event->angleDelta().x();
1146 } else {
1147 d->wheelDeltaRemainder += event->angleDelta().y();
1148 }
1149#else
1150 d->wheelDeltaRemainder += event->angleDelta().y();
1151#endif
1152 const int steps = d->wheelDeltaRemainder / 120;
1153 d->wheelDeltaRemainder -= steps * 120;
1154 if (stepEnabled() & (steps > 0 ? StepUpEnabled : StepDownEnabled))
1155 stepBy(event->modifiers() & d->stepModifier ? steps * 10 : steps);
1156 event->accept();
1157}
1158#endif
1159
1160
1165{
1166 Q_D(QAbstractSpinBox);
1167
1168 d->edit->event(event);
1169 if (event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason) {
1170 selectAll();
1171 }
1173}
1174
1180{
1181 Q_D(QAbstractSpinBox);
1182
1183 if (d->pendingEmit)
1184 d->interpret(EmitIfChanged);
1185
1186 d->reset();
1187 d->edit->event(event);
1188 d->updateEdit();
1190
1191#ifdef QT_KEYPAD_NAVIGATION
1192 // editingFinished() is already emitted on LeaveEditFocus
1193 if (!QApplicationPrivate::keypadNavigationEnabled())
1194#endif
1196}
1197
1203{
1204 Q_D(QAbstractSpinBox);
1205
1206 d->reset();
1207 if (d->pendingEmit)
1208 d->interpret(EmitIfChanged);
1210}
1211
1217{
1218 Q_D(QAbstractSpinBox);
1219 d->reset();
1220 if (d->pendingEmit)
1221 d->interpret(EmitIfChanged);
1223}
1224
1225
1231{
1232 Q_D(QAbstractSpinBox);
1233
1234 bool doStep = false;
1235 if (event->timerId() == d->spinClickThresholdTimerId) {
1236 killTimer(d->spinClickThresholdTimerId);
1237 d->spinClickThresholdTimerId = -1;
1238 d->effectiveSpinRepeatRate = d->buttonState & Keyboard
1240 : d->spinClickTimerInterval;
1241 d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate);
1242 doStep = true;
1243 } else if (event->timerId() == d->spinClickTimerId) {
1244 if (d->accelerate) {
1245 d->acceleration = d->acceleration + (int)(d->effectiveSpinRepeatRate * 0.05);
1246 if (d->effectiveSpinRepeatRate - d->acceleration >= 10) {
1247 killTimer(d->spinClickTimerId);
1248 d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate - d->acceleration);
1249 }
1250 }
1251 doStep = true;
1252 }
1253
1254 if (doStep) {
1255 const bool increaseStepRate = d->keyboardModifiers & d->stepModifier;
1256 const StepEnabled st = stepEnabled();
1257 if (d->buttonState & Up) {
1258 if (!(st & StepUpEnabled)) {
1259 d->reset();
1260 } else {
1261 stepBy(increaseStepRate ? 10 : 1);
1262 }
1263 } else if (d->buttonState & Down) {
1264 if (!(st & StepDownEnabled)) {
1265 d->reset();
1266 } else {
1267 stepBy(increaseStepRate ? -10 : -1);
1268 }
1269 }
1270 return;
1271 }
1273 return;
1274}
1275
1280#if QT_CONFIG(contextmenu)
1282{
1283 Q_D(QAbstractSpinBox);
1284
1285 QPointer<QMenu> menu = d->edit->createStandardContextMenu();
1286 if (!menu)
1287 return;
1288
1289 d->reset();
1290
1291 QAction *selAll = new QAction(tr("&Select All"), menu);
1292#if QT_CONFIG(shortcut)
1293 selAll->setShortcut(QKeySequence::SelectAll);
1294#endif
1295 menu->insertAction(d->edit->d_func()->selectAllAction,
1296 selAll);
1297 menu->removeAction(d->edit->d_func()->selectAllAction);
1298 menu->addSeparator();
1299 const uint se = stepEnabled();
1300 QAction *up = menu->addAction(tr("&Step up"));
1301 up->setEnabled(se & StepUpEnabled);
1302 QAction *down = menu->addAction(tr("Step &down"));
1303 down->setEnabled(se & StepDownEnabled);
1304 menu->addSeparator();
1305
1306 const QPointer<QAbstractSpinBox> that = this;
1307 const QPoint pos = (event->reason() == QContextMenuEvent::Mouse)
1308 ? event->globalPos() : mapToGlobal(QPoint(event->pos().x(), 0)) + QPoint(width() / 2, height() / 2);
1309 const QAction *action = menu->exec(pos);
1310 delete static_cast<QMenu *>(menu);
1311 if (that && action) {
1312 if (action == up) {
1313 stepBy(1);
1314 } else if (action == down) {
1315 stepBy(-1);
1316 } else if (action == selAll) {
1317 selectAll();
1318 }
1319 }
1320 event->accept();
1321}
1322#endif // QT_CONFIG(contextmenu)
1323
1329{
1330 Q_D(QAbstractSpinBox);
1331
1332 d->keyboardModifiers = event->modifiers();
1333 d->updateHoverControl(event->position().toPoint());
1334
1335 // If we have a timer ID, update the state
1336 if (d->spinClickTimerId != -1 && d->buttonSymbols != NoButtons) {
1337 const StepEnabled se = stepEnabled();
1338 if ((se & StepUpEnabled) && d->hoverControl == QStyle::SC_SpinBoxUp)
1339 d->updateState(true);
1340 else if ((se & StepDownEnabled) && d->hoverControl == QStyle::SC_SpinBoxDown)
1341 d->updateState(false);
1342 else
1343 d->reset();
1344 event->accept();
1345 }
1346}
1347
1353{
1354 Q_D(QAbstractSpinBox);
1355
1356 d->keyboardModifiers = event->modifiers();
1357 if (event->button() != Qt::LeftButton || d->buttonState != None) {
1358 return;
1359 }
1360
1361 d->updateHoverControl(event->position().toPoint());
1362 event->accept();
1363
1364 const StepEnabled se = (d->buttonSymbols == NoButtons) ? StepEnabled(StepNone) : stepEnabled();
1365 if ((se & StepUpEnabled) && d->hoverControl == QStyle::SC_SpinBoxUp) {
1366 d->updateState(true);
1367 } else if ((se & StepDownEnabled) && d->hoverControl == QStyle::SC_SpinBoxDown) {
1368 d->updateState(false);
1369 } else {
1370 event->ignore();
1371 }
1372}
1373
1378{
1379 Q_D(QAbstractSpinBox);
1380
1381 d->keyboardModifiers = event->modifiers();
1382 if ((d->buttonState & Mouse) != 0)
1383 d->reset();
1384 event->accept();
1385}
1386
1387// --- QAbstractSpinBoxPrivate ---
1388
1395 : pendingEmit(false), readOnly(false), wrapping(false),
1396 ignoreCursorPositionChanged(false), frame(true), accelerate(false), keyboardTracking(true),
1397 cleared(false), ignoreUpdateEdit(false), showGroupSeparator(false)
1398{
1399}
1400
1401/*
1402 \internal
1403 Called when the QAbstractSpinBoxPrivate is destroyed
1404*/
1406{
1407}
1408
1415{
1416 Q_Q(QAbstractSpinBox);
1417 QRect lastHoverRect = hoverRect;
1418 QStyle::SubControl lastHoverControl = hoverControl;
1419 bool doesHover = q->testAttribute(Qt::WA_Hover);
1420 if (lastHoverControl != newHoverControl(pos) && doesHover) {
1421 q->update(lastHoverRect);
1422 q->update(hoverRect);
1423 return true;
1424 }
1425 return !doesHover;
1426}
1427
1434{
1435 Q_Q(QAbstractSpinBox);
1436
1437 QStyleOptionSpinBox opt;
1438 q->initStyleOption(&opt);
1439 opt.subControls = QStyle::SC_All;
1440 hoverControl = q->style()->hitTestComplexControl(QStyle::CC_SpinBox, &opt, pos, q);
1441 hoverRect = q->style()->subControlRect(QStyle::CC_SpinBox, &opt, hoverControl, q);
1442 return hoverControl;
1443}
1444
1451{
1453 if (specialValueText.size() == 0 || text != specialValueText) {
1454 int from = 0;
1455 int size = text.size();
1456 bool changed = false;
1457 if (prefix.size() && text.startsWith(prefix)) {
1458 from += prefix.size();
1459 size -= from;
1460 changed = true;
1461 }
1462 if (suffix.size() && text.endsWith(suffix)) {
1463 size -= suffix.size();
1464 changed = true;
1465 }
1466 if (changed)
1467 text = text.mid(from, size);
1468 }
1469
1470 const int s = text.size();
1471 text = text.trimmed();
1472 if (pos)
1473 (*pos) -= (s - text.size());
1474 return text.toString();
1475
1476}
1477
1479{
1480 Q_Q(QAbstractSpinBox);
1481 QStyleOptionSpinBox opt;
1482 q->initStyleOption(&opt);
1483 opt.subControls = QStyle::SC_SpinBoxEditField;
1484 edit->setGeometry(q->style()->subControlRect(QStyle::CC_SpinBox, &opt,
1486}
1493{
1494 return (value == minimum && !specialValueText.isEmpty());
1495}
1496
1503{
1504}
1505
1514{
1515 Q_Q(QAbstractSpinBox);
1516
1517 if (keyboardTracking) {
1518 QString tmp = t;
1519 int pos = edit->cursorPosition();
1520 QValidator::State state = q->validate(tmp, pos);
1522 const QVariant v = valueFromText(tmp);
1523 setValue(v, EmitIfChanged, tmp != t);
1524 pendingEmit = false;
1525 } else {
1526 pendingEmit = true;
1527 }
1528 } else {
1529 pendingEmit = true;
1530 }
1531}
1532
1544{
1547
1548 bool allowSelection = true;
1549 int pos = -1;
1550 if (newpos < prefix.size() && newpos != 0) {
1551 if (oldpos == 0) {
1552 allowSelection = false;
1553 pos = prefix.size();
1554 } else {
1555 pos = oldpos;
1556 }
1557 } else if (newpos > edit->text().size() - suffix.size()
1558 && newpos != edit->text().size()) {
1559 if (oldpos == edit->text().size()) {
1560 pos = edit->text().size() - suffix.size();
1561 allowSelection = false;
1562 } else {
1563 pos = edit->text().size();
1564 }
1565 }
1566 if (pos != -1) {
1567 const int selSize = edit->selectionStart() >= 0 && allowSelection
1568 ? (edit->selectedText().size()
1569 * (newpos < pos ? -1 : 1)) - newpos + pos
1570 : 0;
1571
1572 const QSignalBlocker blocker(edit);
1573 if (selSize != 0) {
1574 edit->setSelection(pos - selSize, selSize);
1575 } else {
1577 }
1578 }
1580 }
1581}
1582
1590{
1591 Q_Q(QAbstractSpinBox);
1592
1593 q->setLineEdit(new QLineEdit(q));
1594 edit->setObjectName("qt_spinbox_lineedit"_L1);
1595 validator = new QSpinBoxValidator(q, this);
1597
1598 QStyleOptionSpinBox opt;
1599 // ### This is called from the ctor and thus we shouldn't call initStyleOption yet
1600 // ### as we only call the base class implementation of initStyleOption called.
1601 q->initStyleOption(&opt);
1604 q->setFocusPolicy(Qt::WheelFocus);
1606 q->setAttribute(Qt::WA_InputMethodEnabled);
1607
1608 q->setAttribute(Qt::WA_MacShowFocusRect);
1609}
1610
1619{
1620 Q_Q(QAbstractSpinBox);
1621
1622 buttonState = None;
1623 if (q) {
1624 if (spinClickTimerId != -1)
1625 q->killTimer(spinClickTimerId);
1626 if (spinClickThresholdTimerId != -1)
1627 q->killTimer(spinClickThresholdTimerId);
1629 acceleration = 0;
1630 q->update();
1631 }
1632}
1633
1640void QAbstractSpinBoxPrivate::updateState(bool up, bool fromKeyboard /* = false */)
1641{
1642 Q_Q(QAbstractSpinBox);
1643 if ((up && (buttonState & Up)) || (!up && (buttonState & Down)))
1644 return;
1645 reset();
1646 if (q && (q->stepEnabled() & (up ? QAbstractSpinBox::StepUpEnabled
1648 buttonState = (up ? Up : Down) | (fromKeyboard ? Keyboard : Mouse);
1649 int steps = up ? 1 : -1;
1651 steps *= 10;
1652 q->stepBy(steps);
1654#if QT_CONFIG(accessibility)
1655 QAccessibleValueChangeEvent event(q, value);
1656 QAccessible::updateAccessibility(&event);
1657#endif
1658 }
1659}
1660
1661
1669void QAbstractSpinBox::initStyleOption(QStyleOptionSpinBox *option) const
1670{
1671 if (!option)
1672 return;
1673
1674 Q_D(const QAbstractSpinBox);
1675 option->initFrom(this);
1676 option->activeSubControls = QStyle::SC_None;
1677 option->buttonSymbols = d->buttonSymbols;
1678 option->subControls = QStyle::SC_SpinBoxEditField;
1679 if (style()->styleHint(QStyle::SH_SpinBox_ButtonsInsideFrame, nullptr, this))
1680 option->subControls |= QStyle::SC_SpinBoxFrame;
1681 if (d->buttonSymbols != QAbstractSpinBox::NoButtons) {
1683 if (d->buttonState & Up) {
1684 option->activeSubControls = QStyle::SC_SpinBoxUp;
1685 } else if (d->buttonState & Down) {
1686 option->activeSubControls = QStyle::SC_SpinBoxDown;
1687 }
1688 }
1689
1690 if (d->buttonState) {
1691 option->state |= QStyle::State_Sunken;
1692 } else {
1693 option->activeSubControls = d->hoverControl;
1694 }
1695
1696 option->stepEnabled = style()->styleHint(QStyle::SH_SpinControls_DisableOnBounds, nullptr, this)
1697 ? stepEnabled()
1699
1700 option->frame = d->frame;
1701}
1702
1712{
1713 QVariant v = val;
1714 if (!wrapping || steps == 0 || old.isNull()) {
1715 if (variantCompare(v, minimum) < 0) {
1716 v = wrapping ? maximum : minimum;
1717 }
1718 if (variantCompare(v, maximum) > 0) {
1719 v = wrapping ? minimum : maximum;
1720 }
1721 } else {
1722 const bool wasMin = old == minimum;
1723 const bool wasMax = old == maximum;
1724 const int oldcmp = variantCompare(v, old);
1725 const int maxcmp = variantCompare(v, maximum);
1726 const int mincmp = variantCompare(v, minimum);
1727 const bool wrapped = (oldcmp > 0 && steps < 0) || (oldcmp < 0 && steps > 0);
1728 if (maxcmp > 0) {
1729 v = ((wasMax && !wrapped && steps > 0) || (steps < 0 && !wasMin && wrapped))
1730 ? minimum : maximum;
1731 } else if (wrapped && (maxcmp > 0 || mincmp < 0)) {
1732 v = ((wasMax && steps > 0) || (!wasMin && steps < 0)) ? minimum : maximum;
1733 } else if (mincmp < 0) {
1734 v = (!wasMax && !wasMin ? minimum : maximum);
1735 }
1736 }
1737
1738 return v;
1739}
1740
1749 bool doUpdate)
1750{
1751 Q_Q(QAbstractSpinBox);
1752 const QVariant old = value;
1753 value = bound(val);
1754 pendingEmit = false;
1755 cleared = false;
1756 if (doUpdate) {
1757 updateEdit();
1758 }
1759 q->update();
1760
1761 if (ep == AlwaysEmit || (ep == EmitIfChanged && old != value)) {
1762 emitSignals(ep, old);
1763 }
1764}
1765
1773{
1774 Q_Q(QAbstractSpinBox);
1776 return;
1778 if (newText == edit->displayText() || cleared)
1779 return;
1780
1781 const bool empty = edit->text().isEmpty();
1782 int cursor = edit->cursorPosition();
1783 int selsize = edit->selectedText().size();
1784 const QSignalBlocker blocker(edit);
1785 edit->setText(newText);
1786
1787 if (!specialValue()) {
1789
1790 if (selsize > 0) {
1791 edit->setSelection(cursor, selsize);
1792 } else {
1793 edit->setCursorPosition(empty ? prefix.size() : cursor);
1794 }
1795 }
1796 q->update();
1797}
1798
1806{
1807 Q_Q(QAbstractSpinBox);
1808
1809 clearCache();
1810 minimum = min;
1811 maximum = (variantCompare(min, max) < 0 ? max : min);
1813 cachedMinimumSizeHint = QSize(); // minimumSizeHint cares about min/max
1814
1815 reset();
1816 if (!(bound(value) == value)) {
1818 } else if (value == minimum && !specialValueText.isEmpty()) {
1819 updateEdit();
1820 }
1821
1822 q->updateGeometry();
1823}
1824
1832{
1833 QVariant ret;
1834 switch (type) {
1835 case QMetaType::Int: ret = QVariant(0); break;
1836 case QMetaType::Double: ret = QVariant(0.0); break;
1837 default: break;
1838 }
1839 return ret;
1840}
1841
1854{
1855 return QString();
1856}
1857
1870{
1871 return QVariant();
1872}
1881{
1882 Q_Q(QAbstractSpinBox);
1884 return;
1885
1887 bool doInterpret = true;
1888 QString tmp = edit->displayText();
1889 int pos = edit->cursorPosition();
1890 const int oldpos = pos;
1891
1892 if (q->validate(tmp, pos) != QValidator::Acceptable) {
1893 const QString copy = tmp;
1894 q->fixup(tmp);
1895 QASBDEBUG() << "QAbstractSpinBoxPrivate::interpret() text '"
1896 << edit->displayText()
1897 << "' >> '" << copy << '\''
1898 << "' >> '" << tmp << '\'';
1899
1900 doInterpret = tmp != copy && (q->validate(tmp, pos) == QValidator::Acceptable);
1901 if (!doInterpret) {
1904 }
1905 }
1906 if (doInterpret) {
1907 v = valueFromText(tmp);
1908 }
1909 clearCache();
1910 setValue(v, ep, true);
1911 if (oldpos != pos)
1913}
1914
1916{
1917 cachedText.clear();
1920}
1921
1923{
1924 Q_UNUSED(steps);
1925 return singleStep;
1926}
1927
1928// --- QSpinBoxValidator ---
1929
1936 : QValidator(qp), qptr(qp), dptr(dp)
1937{
1938 setObjectName("qt_spinboxvalidator"_L1);
1939}
1940
1949{
1950 if (dptr->specialValueText.size() > 0 && input == dptr->specialValueText)
1952
1953 if (!dptr->prefix.isEmpty() && !input.startsWith(dptr->prefix)) {
1954 input.prepend(dptr->prefix);
1955 pos += dptr->prefix.size();
1956 }
1957
1958 if (!dptr->suffix.isEmpty() && !input.endsWith(dptr->suffix))
1959 input.append(dptr->suffix);
1960
1961 return qptr->validate(input, pos);
1962}
1969{
1970 qptr->fixup(input);
1971}
1972
1973// --- global ---
1974
1981{
1982 QVariant ret;
1983 if (Q_UNLIKELY(arg1.userType() != arg2.userType()))
1984 qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)",
1985 arg1.typeName(), arg2.typeName(), __FILE__, __LINE__);
1986 switch (arg1.userType()) {
1987 case QMetaType::Int: {
1988 const int int1 = arg1.toInt();
1989 const int int2 = arg2.toInt();
1990 if (int1 > 0 && (int2 >= INT_MAX - int1)) {
1991 // The increment overflows
1992 ret = QVariant(INT_MAX);
1993 } else if (int1 < 0 && (int2 <= INT_MIN - int1)) {
1994 // The increment underflows
1995 ret = QVariant(INT_MIN);
1996 } else {
1997 ret = QVariant(int1 + int2);
1998 }
1999 break;
2000 }
2001 case QMetaType::Double: ret = QVariant(arg1.toDouble() + arg2.toDouble()); break;
2002#if QT_CONFIG(datetimeparser)
2003 case QMetaType::QDateTime: {
2004 QDateTime a2 = arg2.toDateTime();
2005 QDateTime a1 = arg1.toDateTime().addDays(QDATETIMEEDIT_DATE_MIN.daysTo(a2.date()));
2006 a1.setTime(a1.time().addMSecs(a2.time().msecsSinceStartOfDay()));
2007 ret = QVariant(a1);
2008 break;
2009 }
2010#endif // datetimeparser
2011 default: break;
2012 }
2013 return ret;
2014}
2015
2016
2023{
2024 QVariant ret;
2025 if (Q_UNLIKELY(arg1.userType() != arg2.userType()))
2026 qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)",
2027 arg1.typeName(), arg2.typeName(), __FILE__, __LINE__);
2028 switch (arg1.userType()) {
2029 case QMetaType::Int: ret = QVariant(arg1.toInt() - arg2.toInt()); break;
2030 case QMetaType::Double: ret = QVariant(arg1.toDouble() - arg2.toDouble()); break;
2031 case QMetaType::QDateTime: {
2032 QDateTime a1 = arg1.toDateTime();
2033 QDateTime a2 = arg2.toDateTime();
2034 int days = a2.daysTo(a1);
2035 int secs = a2.secsTo(a1);
2036 int msecs = qMax(0, a1.time().msec() - a2.time().msec());
2037 if (days < 0 || secs < 0 || msecs < 0) {
2038 ret = arg1;
2039 } else {
2040 QDateTime dt = a2.addDays(days).addSecs(secs);
2041 if (msecs > 0)
2042 dt.setTime(dt.time().addMSecs(msecs));
2043 ret = QVariant(dt);
2044 }
2045 }
2046 default: break;
2047 }
2048 return ret;
2049}
2050
2056QVariant operator*(const QVariant &arg1, double multiplier)
2057{
2058 QVariant ret;
2059
2060 switch (arg1.userType()) {
2061 case QMetaType::Int:
2062 ret = static_cast<int>(qBound<double>(INT_MIN, arg1.toInt() * multiplier, INT_MAX));
2063 break;
2064 case QMetaType::Double: ret = QVariant(arg1.toDouble() * multiplier); break;
2065#if QT_CONFIG(datetimeparser)
2066 case QMetaType::QDateTime: {
2067 double days = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDateTime().date()) * multiplier;
2068 const qint64 daysInt = qint64(days);
2069 days -= daysInt;
2070 qint64 msecs = qint64(arg1.toDateTime().time().msecsSinceStartOfDay() * multiplier
2071 + days * (24 * 3600 * 1000));
2072 ret = QDATETIMEEDIT_DATE_MIN.addDays(daysInt).startOfDay().addMSecs(msecs);
2073 break;
2074 }
2075#endif // datetimeparser
2076 default: ret = arg1; break;
2077 }
2078
2079 return ret;
2080}
2081
2082
2083
2084double operator/(const QVariant &arg1, const QVariant &arg2)
2085{
2086 double a1 = 0;
2087 double a2 = 0;
2088
2089 switch (arg1.userType()) {
2090 case QMetaType::Int:
2091 a1 = (double)arg1.toInt();
2092 a2 = (double)arg2.toInt();
2093 break;
2094 case QMetaType::Double:
2095 a1 = arg1.toDouble();
2096 a2 = arg2.toDouble();
2097 break;
2098#if QT_CONFIG(datetimeparser)
2099 case QMetaType::QDateTime:
2100 a1 = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDate());
2101 a2 = QDATETIMEEDIT_DATE_MIN.daysTo(arg2.toDate());
2102 a1 += arg1.toDateTime().time().msecsSinceStartOfDay() / (36e5 * 24);
2103 a2 += arg2.toDateTime().time().msecsSinceStartOfDay() / (36e5 * 24);
2104 break;
2105#endif // datetimeparser
2106 default: break;
2107 }
2108
2109 return (a1 != 0 && a2 != 0) ? (a1 / a2) : 0.0;
2110}
2111
2113{
2114 switch (arg2.userType()) {
2115 case QMetaType::QDate:
2116 Q_ASSERT_X(arg1.userType() == QMetaType::QDate, "QAbstractSpinBoxPrivate::variantCompare",
2117 qPrintable(QString::fromLatin1("Internal error 1 (%1)").
2118 arg(QString::fromLatin1(arg1.typeName()))));
2119 if (arg1.toDate() == arg2.toDate()) {
2120 return 0;
2121 } else if (arg1.toDate() < arg2.toDate()) {
2122 return -1;
2123 } else {
2124 return 1;
2125 }
2126 case QMetaType::QTime:
2127 Q_ASSERT_X(arg1.userType() == QMetaType::QTime, "QAbstractSpinBoxPrivate::variantCompare",
2128 qPrintable(QString::fromLatin1("Internal error 2 (%1)").
2129 arg(QString::fromLatin1(arg1.typeName()))));
2130 if (arg1.toTime() == arg2.toTime()) {
2131 return 0;
2132 } else if (arg1.toTime() < arg2.toTime()) {
2133 return -1;
2134 } else {
2135 return 1;
2136 }
2137
2138
2139 case QMetaType::QDateTime:
2140 if (arg1.toDateTime() == arg2.toDateTime()) {
2141 return 0;
2142 } else if (arg1.toDateTime() < arg2.toDateTime()) {
2143 return -1;
2144 } else {
2145 return 1;
2146 }
2147 case QMetaType::Int:
2148 if (arg1.toInt() == arg2.toInt()) {
2149 return 0;
2150 } else if (arg1.toInt() < arg2.toInt()) {
2151 return -1;
2152 } else {
2153 return 1;
2154 }
2155 case QMetaType::Double:
2156 if (arg1.toDouble() == arg2.toDouble()) {
2157 return 0;
2158 } else if (arg1.toDouble() < arg2.toDouble()) {
2159 return -1;
2160 } else {
2161 return 1;
2162 }
2164 if (arg2.userType() == QMetaType::UnknownType)
2165 return 0;
2166 Q_FALLTHROUGH();
2167 default:
2168 Q_ASSERT_X(0, "QAbstractSpinBoxPrivate::variantCompare",
2169 qPrintable(QString::fromLatin1("Internal error 3 (%1 %2)").
2170 arg(QString::fromLatin1(arg1.typeName()),
2171 QString::fromLatin1(arg2.typeName()))));
2172 }
2173 return -2;
2174}
2175
2177 const QVariant &value,
2178 const QVariant &max)
2179{
2180 Q_ASSERT(variantCompare(min, max) <= 0);
2181 if (variantCompare(min, value) < 0) {
2182 const int compMax = variantCompare(value, max);
2183 return (compMax < 0 ? value : max);
2184 } else {
2185 return min;
2186 }
2187}
2188
2189
2191
2192#include "moc_qabstractspinbox.cpp"
virtual QVariant valueFromText(const QString &input) const
virtual void emitSignals(EmitPolicy ep, const QVariant &old)
virtual QStyle::SubControl newHoverControl(const QPoint &pos)
static QVariant variantBound(const QVariant &min, const QVariant &value, const QVariant &max)
virtual QVariant getZeroVariant() const
virtual void setRange(const QVariant &min, const QVariant &max)
QSpinBoxValidator * validator
static int variantCompare(const QVariant &arg1, const QVariant &arg2)
QString stripped(const QString &text, int *pos=nullptr) const
Qt::KeyboardModifier stepModifier
Qt::KeyboardModifiers keyboardModifiers
void _q_editorTextChanged(const QString &)
virtual void interpret(EmitPolicy ep)
QStyle::SubControl hoverControl
virtual void updateEditFieldGeometry()
virtual QString textFromValue(const QVariant &n) const
void updateState(bool up, bool fromKeyboard=false)
virtual void _q_editorCursorPositionChanged(int oldpos, int newpos)
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)
bool updateHoverControl(const QPoint &pos)
QAbstractSpinBox::CorrectionMode correctionMode
virtual QVariant calculateAdaptiveDecimalStep(int steps) const
The QAbstractSpinBox class provides a spinbox and a line edit to display values.
QString specialValueText
the special-value text
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 setButtonSymbols(ButtonSymbols bs)
void interpretText()
This function interprets the text of the spin box.
void setSpecialValueText(const QString &txt)
bool isGroupSeparatorShown() const
void hideEvent(QHideEvent *event) override
\reimp
void mouseMoveEvent(QMouseEvent *event) override
\reimp
void setCorrectionMode(CorrectionMode cm)
void changeEvent(QEvent *event) override
\reimp
void paintEvent(QPaintEvent *event) override
\reimp
void resizeEvent(QResizeEvent *event) override
\reimp
void setKeyboardTracking(bool kt)
CorrectionMode correctionMode
the mode to correct an \l{QValidator::}{Intermediate} value if editing finishes
Qt::Alignment alignment
the alignment of the spin box
ButtonSymbols buttonSymbols
the current button symbol mode
void stepUp()
Steps up by one linestep Calling this slot is analogous to calling stepBy(1);.
void mousePressEvent(QMouseEvent *event) override
\reimp
~QAbstractSpinBox()
Called when the QAbstractSpinBox is destroyed.
QAbstractSpinBox(QWidget *parent=nullptr)
Constructs an abstract spinbox with the given parent with default \l wrapping, and \l alignment prope...
virtual void fixup(QString &input) const
This virtual function is called by the QAbstractSpinBox if the input is not validated to QValidator::...
bool keyboardTracking
whether keyboard tracking is enabled for the spinbox.
void setLineEdit(QLineEdit *edit)
Sets the line edit of the spinbox to be lineEdit instead of the current line edit widget.
virtual void stepBy(int steps)
Virtual function that is called whenever the user triggers a step.
void setAlignment(Qt::Alignment flag)
void setAccelerated(bool on)
QSize minimumSizeHint() const override
\reimp
void showEvent(QShowEvent *event) override
\reimp
void stepDown()
Steps down by one linestep Calling this slot is analogous to calling stepBy(-1);.
void closeEvent(QCloseEvent *event) override
\reimp
CorrectionMode
This enum type describes the mode the spinbox will use to correct an \l{QValidator::}{Intermediate} v...
virtual void initStyleOption(QStyleOptionSpinBox *option) const
Initialize option with the values from this QSpinBox.
void keyReleaseEvent(QKeyEvent *event) override
\reimp
void timerEvent(QTimerEvent *event) override
\reimp
QLineEdit * lineEdit() const
This function returns a pointer to the line edit of the spin box.
bool isAccelerated() const
QSize sizeHint() const override
\reimp
bool event(QEvent *event) override
\reimp
void mouseReleaseEvent(QMouseEvent *event) override
\reimp
void focusOutEvent(QFocusEvent *event) override
\reimp
virtual StepEnabled stepEnabled() const
Virtual function that determines whether stepping up and down is legal at any given time.
void setGroupSeparatorShown(bool shown)
bool wrapping
whether the spin box is circular.
bool hasAcceptableInput() const
virtual void clear()
Clears the lineedit of all text but prefix and suffix.
void keyPressEvent(QKeyEvent *event) override
\reimp
QVariant inputMethodQuery(Qt::InputMethodQuery) const override
\reimp
ButtonSymbols
This enum type describes the symbols that can be displayed on the buttons in a spin box.
virtual QValidator::State validate(QString &input, int &pos) const
This virtual function is called by the QAbstractSpinBox to determine whether input is valid.
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
void setEnabled(bool)
Definition qaction.cpp:927
The QCloseEvent class contains parameters that describe a close event.
Definition qevent.h:561
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:593
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
\inmodule QtCore\reentrant
Definition qdatetime.h:257
void setTime(QTime time)
Sets the time part of this datetime to time.
QTime time() const
Returns the time part of the datetime.
\inmodule QtCore
Definition qcoreevent.h:45
@ EnabledChange
Definition qcoreevent.h:134
@ LayoutDirectionChange
Definition qcoreevent.h:124
@ ApplicationLayoutDirectionChange
Definition qcoreevent.h:92
@ ReadOnlyChange
Definition qcoreevent.h:145
@ ShortcutOverride
Definition qcoreevent.h:158
@ InputMethod
Definition qcoreevent.h:120
@ StyleChange
Definition qcoreevent.h:136
@ LocaleChange
Definition qcoreevent.h:122
@ FontChange
Definition qcoreevent.h:133
@ ActivationChange
Definition qcoreevent.h:135
@ HoverLeave
Definition qcoreevent.h:176
@ HoverEnter
Definition qcoreevent.h:175
@ HoverMove
Definition qcoreevent.h:177
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
\reentrant \inmodule QtGui
int horizontalAdvance(const QString &, int len=-1) const
Returns the horizontal advance in pixels of the first len characters of text.
static QStyleHints * styleHints()
Returns the application's style hints.
QString platformName
The name of the underlying platform plugin.
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition qevent.h:585
\inmodule QtGui
Definition qevent.h:245
The QKeyEvent class describes a key event.
Definition qevent.h:423
The QLineEdit widget is a one-line text editor.
Definition qlineedit.h:28
int cursorPosition
the current cursor position for this line edit.
Definition qlineedit.h:37
void setValidator(const QValidator *)
Sets the validator for values of line edit to v.
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 displayText
the displayed text.
Definition qlineedit.h:36
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
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
QAction * exec()
Executes this menu synchronously.
Definition qmenu.cpp:2586
QAction * addSeparator()
This convenience function creates a new separator action, i.e.
Definition qmenu.cpp:1899
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3124
\inmodule QtGui
Definition qevent.h:195
int startTimer(int interval, Qt::TimerType timerType=Qt::CoarseTimer)
This is an overloaded function that will start a timer of type timerType and a timeout of interval mi...
Definition qobject.cpp:1792
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
virtual void timerEvent(QTimerEvent *event)
This event handler can be reimplemented in a subclass to receive timer events for the object.
Definition qobject.cpp:1433
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
Definition qobject.h:114
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition qobject.cpp:1872
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
\inmodule QtCore\reentrant
Definition qpoint.h:23
\inmodule QtCore
Definition qpointer.h:18
\inmodule QtCore\reentrant
Definition qrect.h:30
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:547
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:577
Exception-safe wrapper around QObject::blockSignals().
Definition qobject.h:443
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
\inmodule QtCore
Definition qsize.h:25
void fixup(QString &) const override
QSpinBoxValidator(QAbstractSpinBox *qptr, QAbstractSpinBoxPrivate *dptr)
QValidator::State validate(QString &input, int &) const override
\inmodule QtCore
Definition qstringview.h:76
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition qstring.cpp:5299
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5710
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1107
qsizetype size() const
Returns the number of characters in this string.
Definition qstring.h:182
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
Definition qstring.cpp:5204
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition qstring.cpp:5350
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
QString trimmed() const &
Definition qstring.h:380
qreal keyboardAutoRepeatRateF
the rate, in events per second, in which additional repeated key presses will automatically be genera...
Definition qstylehints.h:25
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget.
@ State_Sunken
Definition qstyle.h:69
@ CT_SpinBox
Definition qstyle.h:560
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...
@ SH_SpinBox_AnimateButton
Definition qstyle.h:625
@ SH_SpinBox_ClickAutoRepeatRate
Definition qstyle.h:627
@ SH_SpinControls_DisableOnBounds
Definition qstyle.h:639
@ SH_SpinBox_SelectOnStep
Definition qstyle.h:704
@ SH_SpinBox_StepModifier
Definition qstyle.h:701
@ SH_SpinBox_ClickAutoRepeatThreshold
Definition qstyle.h:666
@ SH_SpinBox_ButtonsInsideFrame
Definition qstyle.h:700
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
@ CC_SpinBox
Definition qstyle.h:332
SubControl
This enum describes the available sub controls.
Definition qstyle.h:347
@ SC_All
Definition qstyle.h:400
@ SC_SpinBoxDown
Definition qstyle.h:360
@ SC_SpinBoxUp
Definition qstyle.h:359
@ SC_None
Definition qstyle.h:348
@ SC_SpinBoxFrame
Definition qstyle.h:361
@ SC_SpinBoxEditField
Definition qstyle.h:362
QTime addMSecs(int ms) const
Returns a QTime object containing a time ms milliseconds later than the time of this object (or earli...
\inmodule QtCore
Definition qcoreevent.h:359
The QValidator class provides validation of input text.
Definition qvalidator.h:24
State
This enum type defines the states in which a validated string can exist.
Definition qvalidator.h:30
\inmodule QtCore
Definition qvariant.h:64
void clear()
Convert this variant to type QMetaType::UnknownType and free up any resources used.
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
bool isNull() const
Returns true if this is a null variant, false otherwise.
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
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
virtual void hideEvent(QHideEvent *event)
This event handler can be reimplemented in a subclass to receive widget hide events.
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
virtual void closeEvent(QCloseEvent *event)
This event handler is called with the given event when Qt receives a window close request for a top-l...
Definition qwidget.cpp:9902
QPointF mapToGlobal(const QPointF &) const
Translates the widget coordinate pos to global screen coordinates.
int width
the width of the widget excluding any window frame
Definition qwidget.h:114
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
QFontMetrics fontMetrics() const
Returns the font metrics for the widget's current font.
Definition qwidget.h:847
virtual void focusInEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition qwidget.cpp:9711
int height
the height of the widget excluding any window frame
Definition qwidget.h:115
void insertAction(QAction *before, QAction *action)
Inserts the action action to this widget's list of actions, before the action before.
Definition qwidget.cpp:3149
void ensurePolished() const
Ensures that the widget and its children have been polished by QStyle (i.e., have a proper font and p...
bool isEnabled() const
Definition qwidget.h:814
void update()
Updates the widget unless updates are disabled or the widget is hidden.
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9428
Qt::InputMethodHints inputMethodHints
What input method specific hints the widget has.
Definition qwidget.h:178
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8912
QStyle * style() const
Definition qwidget.cpp:2607
virtual void focusOutEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition qwidget.cpp:9737
virtual void resizeEvent(QResizeEvent *event)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition qwidget.cpp:9868
bool isActiveWindow
whether this widget's window is the active window
Definition qwidget.h:139
void removeAction(QAction *action)
Removes the action action from this widget's list of actions.
Definition qwidget.cpp:3193
void updateMicroFocus(Qt::InputMethodQuery query=Qt::ImQueryAll)
Updates the widget's micro focus and informs input methods that the state specified by query has chan...
bool isVisible() const
Definition qwidget.h:874
virtual void contextMenuEvent(QContextMenuEvent *event)
This event handler, for event event, can be reimplemented in a subclass to receive widget context men...
Definition qwidget.cpp:9921
EGLImageKHR int int EGLuint64KHR * modifiers
QString text
QCursor cursor
void textChanged(const QString &newText)
double e
QStyleOptionButton opt
else opt state
[0]
Combined button and popup list for selecting options.
InputMethodQuery
@ ImHints
@ LeftButton
Definition qnamespace.h:57
@ WA_Hover
Definition qnamespace.h:339
@ WA_MacShowFocusRect
Definition qnamespace.h:358
@ WA_InputMethodEnabled
Definition qnamespace.h:294
@ WheelFocus
Definition qnamespace.h:110
@ MouseEventNotSynthesized
@ Key_Select
@ Key_Return
Definition qnamespace.h:662
@ Key_Right
Definition qnamespace.h:674
@ Key_Enter
Definition qnamespace.h:663
@ Key_PageUp
Definition qnamespace.h:676
@ Key_U
Definition qnamespace.h:566
@ Key_Left
Definition qnamespace.h:672
@ Key_Up
Definition qnamespace.h:673
@ Key_Down
Definition qnamespace.h:675
@ Key_PageDown
Definition qnamespace.h:677
@ Key_Back
Definition qnamespace.h:841
@ Key_Home
Definition qnamespace.h:670
@ Key_End
Definition qnamespace.h:671
KeyboardModifier
@ ShiftModifier
@ ControlModifier
@ NoContextMenu
@ BacktabFocusReason
@ TabFocusReason
QVariant operator-(const QVariant &arg1, const QVariant &arg2)
#define QASBDEBUG
QVariant operator*(const QVariant &arg1, double multiplier)
double operator/(const QVariant &arg1, const QVariant &arg2)
QVariant operator+(const QVariant &arg1, const QVariant &arg2)
@ Keyboard
@ EmitIfChanged
@ NeverEmit
@ AlwaysEmit
static jboolean copy(JNIEnv *, jobject)
#define Q_FALLTHROUGH()
#define Q_UNLIKELY(x)
#define QDATETIMEEDIT_DATE_MIN
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qWarning
Definition qlogging.h:162
return ret
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:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum type
GLboolean enable
GLfloat GLfloat GLfloat GLfloat h
struct _cl_event * event
GLenum query
GLuint GLfloat * val
GLuint GLuint GLuint GLuint arg1
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLdouble s
[6]
Definition qopenglext.h:235
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
SSL_CTX int(*) void arg)
#define qPrintable(string)
Definition qstring.h:1391
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
#define a2
#define a1
#define tr(X)
#define emit
#define Q_UNUSED(x)
unsigned int uint
Definition qtypes.h:29
long long qint64
Definition qtypes.h:55
QLineEdit * lineEdit
QFrame frame
[0]
QMenu menu
[5]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent