Unsolved How to restrict QSpinBox value to 1 to 100?
-
@JonB said in How to restrict QSpinBox value to 1 to 100?:
@KillerSmath
How would your regexp allow a value like, say,23
? How would it prevent, say,999
?I just said a hypothetical example.
-
@KillerSmath
Oh, OK, some posters here will type in whatever you offer and then complain if it doesn't work as-is! -
@JonB said in How to restrict QSpinBox value to 1 to 100?:
@KillerSmath
Oh, OK, some posters here will type in whatever you offer and then complain if it doesn't work as-is!an easy mode to write this regular expression is
0|100|[1-9][0-9]?
-
@KillerSmath
Yep. For completeness, since the OP states he wants to disallow0
, if he wants to copy this it should be100|[1-9][0-9]?
. -
@JonB said in How to restrict QSpinBox value to 1 to 100?:
@KillerSmath
Yep. For completeness, since the OP states he wants to disallow0
, if he wants to copy this it should be100|[1-9][0-9]?
.Yep, thank you, i forgot this part. xD
-
To be correct:
^[1-9][0-9]?$|^100$
. Otherwise you'll be matching "numbers in numbers" -
@SGaist said in How to restrict QSpinBox value to 1 to 100?:
To be correct:
^[1-9][0-9]?$|^100$
. Otherwise you'll be matching "numbers in numbers"Yes, use the delimiters to apply this regular expression on full string.
-
To be correct:
^[1-9][0-9]?$|^100$
. Otherwise you'll be matching "numbers in numbers"But for
QAbstractSpinBox::validate()
I assume it uses http://doc.qt.io/qt-5/qregularexpressionvalidator.html#details, which states:QRegularExpressionValidator automatically wraps the regular expression in the \A and \z anchors; in other words, it always attempts to do an exact match.
?
-
@JonB said in How to restrict QSpinBox value to 1 to 100?:
To be correct:
^[1-9][0-9]?$|^100$
. Otherwise you'll be matching "numbers in numbers"But for
QAbstractSpinBox::validate()
I assume it uses http://doc.qt.io/qt-5/qregularexpressionvalidator.html#details, which states:QRegularExpressionValidator automatically wraps the regular expression in the \A and \z anchors; in other words, it always attempts to do an exact match.
?
Yes, i found the Qt reposity and i noticed
QAbstractSpinBox::validate()
returns for defaultQValidator::Acceptable
without verification.if the input is not validated to QValidator::Acceptable when Return is pressed or interpretText() is called.
-
@KillerSmath
Not sure your comment is against what I meant?
I was asking @SGaist why it is necessary to put in his^
&$
in the reg exp given that the docs for http://doc.qt.io/qt-5/qregularexpressionvalidator.html#details (seem to me to) state that it will do full match anyway? UnlessQAbstractSpinBox::validate()
does not useQRegularExpressionValidator
? -
@JonB That was for direct
QRegularExpression
use.