[Solved]QRegExpValidator Questions
-
Hi
I have a QLineEdit and to prevent user from entering invalid entries i am using a QValidator. I have QLineEdits where only an integer can be entered and where a float can be entered.
I found QDoubleValidator and QIntValidator but these had some features i didn't liked. For example user can enter dots to a QLineEdit with QIntValidator, which i don't want. Also user can enter dots and commas to a QLineEdit with QDoubleValidator.
So i decided to use QRegExpValidator. For int validating i used
validator = new QRegExpValidator(QRegExp("([-]{0,1})([0-9]{0,9})"));
And for float validating
validator = new QRegExpValidator(QRegExp("([-]{0,1})([0-9]{0,9})([.]{0,1}[0-9]{0,7})"));
I have two questions regarding these
- Can i make it so user can not enter a number bigger or smaller than a value, like it does with QIntValidator?
- The line for float validating i created causes a problem. Currently user can enter fraction numbers without entering a dot first. How can i overcome this, so that user have to enter a dot before entering fraction numbers.
Thanks in advance
-
Hi,
Why not use a QSpinBox and a QDoubleSpin box for the numerical inputs ?
-
You're welcome !
Sure thing
Happy coding !