aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <[email protected]>2025-10-09 10:46:40 +0200
committerShawn Rutledge <[email protected]>2025-10-10 19:31:35 +0200
commitb4a207af6943f63e598aee0a74c102a14cf26b71 (patch)
tree82b82b0362cf330d29e52b84c02a3227c78ebf66
parent96764ff52393abc81aae1b72946297ccb7e7d507 (diff)
IntValidator docs: Provide guidance on intermediate results
Validators in QML do not actually expose the three states (Valid, Invalid, Intermediate) directly, but only support their usage through TextField. This makes it slightly tricky to raise awareness about intermediate results. Nevertheless, we can expand the example to avoid confusion how IntValidator restricts input, and to encourage users to create a visual indicator based on acceptableInput. The color can also be a binding in the snippet. Amends 17a777a5dfa72e47d02c3e6b4c3a137d923d50bc Pick-to: 6.10 6.8 Fixes: QTBUG-85490 Change-Id: Ia3f7d21d6d7c13943cc2469c4ab8f3c00fd2eada Reviewed-by: Shawn Rutledge <[email protected]> Reviewed-by: Edward Welbourne <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]>
-rw-r--r--src/quick/doc/snippets/qml/intvalidator.qml3
-rw-r--r--src/quick/util/qquickvalidator.cpp14
2 files changed, 15 insertions, 2 deletions
diff --git a/src/quick/doc/snippets/qml/intvalidator.qml b/src/quick/doc/snippets/qml/intvalidator.qml
index 71ba774299..f08732742b 100644
--- a/src/quick/doc/snippets/qml/intvalidator.qml
+++ b/src/quick/doc/snippets/qml/intvalidator.qml
@@ -10,7 +10,6 @@ TextInput {
bottom: 0
top: 100
}
- onAcceptableInputChanged:
- color = acceptableInput ? "black" : "red";
+ color: acceptableInput ? "black" : "red";
}
//![0]
diff --git a/src/quick/util/qquickvalidator.cpp b/src/quick/util/qquickvalidator.cpp
index d9b2fa8734..73be06a4ca 100644
--- a/src/quick/util/qquickvalidator.cpp
+++ b/src/quick/util/qquickvalidator.cpp
@@ -29,6 +29,20 @@ QT_BEGIN_NAMESPACE
\snippet qml/intvalidator.qml 0
+ The validator will prevent the submission of text which can't possibly be
+ valid. However, while editing, only easily identified invalidity will be
+ blocked, for example sign conflicts or too many non-zero digits. This can
+ sometimes be surprising. The validator in the example above will for
+ instance allow entering "999", as values consisting of a number of digits
+ equal to or less than the max value are considered "intermediate" --
+ meaning that they are in a state where they are not valid, but could be
+ adjusted to be so. This is intended because the digit that prevents a
+ number from being in range is not necessarily the last digit typed. This
+ also means that an intermediate number can have leading zeros.
+
+ Adding a visual indicator based on TextInput's \l{TextInput::acceptableInput}{acceptableInput}
+ property can make clear to the user whether what they've typed will actually be accepted.
+
\sa DoubleValidator, RegularExpressionValidator, {Validating Input Text}
*/