summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qdatetimeedit_p.h
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-03-17 18:07:15 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-03-20 22:18:00 +0100
commit580e9eedf783ccbdcb67baa3d1a9dcdd53922f86 (patch)
tree746a02c588443b3b9eb1777f63af5c67a783c6df /src/widgets/widgets/qdatetimeedit_p.h
parent30a0787907981da3811390735bf234068fc89944 (diff)
QDateTimeEdit: with keyboardTracking off, allow values outside the range
QDateTimeEdit very aggressively prevents user input that would result in values that are outside the dateTimeRange. While keyboardTracking is on this makes sense, as otherwise the dateTimeChanged signal would be emitted after each section, with a value that is outside the range. However, this prevented users from entering a date that is allowed, but where sections of the date are above or below the respective section in the maximum or minimum value. If keyboardTracking is off, QDateTimeEdit only emits the dateTimeChanged signal at the end of editing, when focus is lost or the return key is pressed, and then it enforces that the value is within the range anyway. This change makes the parser ignore the range during editing if keyboardTracking is off, thus allowing the user to enter a date where temporary values are outside the range. The test makes sure that we don't get signals emitted with out-of-range values, testing both with and without keyboard tracking. Change-Id: I00fb9f1b328a3477163f890c4618b40878657816 Fixes: QTBUG-65 Reviewed-by: Andy Shaw <andy.shaw@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/widgets/widgets/qdatetimeedit_p.h')
-rw-r--r--src/widgets/widgets/qdatetimeedit_p.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/widgets/widgets/qdatetimeedit_p.h b/src/widgets/widgets/qdatetimeedit_p.h
index dcf8863c8b..323246a87b 100644
--- a/src/widgets/widgets/qdatetimeedit_p.h
+++ b/src/widgets/widgets/qdatetimeedit_p.h
@@ -94,8 +94,18 @@ public:
// Override QDateTimeParser:
QString displayText() const override { return edit->text(); }
- QDateTime getMinimum() const override { return minimum.toDateTime(); }
- QDateTime getMaximum() const override { return maximum.toDateTime(); }
+ QDateTime getMinimum() const override
+ {
+ if (keyboardTracking)
+ return minimum.toDateTime();
+ return QDateTimeParser::getMinimum();
+ }
+ QDateTime getMaximum() const override
+ {
+ if (keyboardTracking)
+ return maximum.toDateTime();
+ return QDateTimeParser::getMaximum();
+ }
QLocale locale() const override { return q_func()->locale(); }
QString getAmPmText(AmPm ap, Case cs) const override;
int cursorPosition() const override { return edit ? edit->cursorPosition() : -1; }