[SOLVED] QLineEdit Should accept only integers and " and / characters??
-
Hi.....
I have a QLineEdit & Am using it for a Measurement Conversion Application... In that QLineEdit i have to use only the Integers values. so i used the QDoubleValidator.
@q_LineEdit->setValidator(new QDoubleValidator(this));@
Now i want the QLineEdit to accept only " and / characters to it, as it is required for the conversion application. how can i make my QLineEdit to accept it while using a QDoubleValidator... Pls give ur suggestions....
Thanks & Regards
-
You need to use "QRegExpValidator":http://qt-project.org/doc/qt-4.8/qregexpvalidator.html.
-
Thanks for your suggestion sierdzio.
If i use a QRegExpValidator, it will acept all the characters. (including alphabets too). I don't want my QLineEdit to accept the alphabets or any other characters except this " and / in it.
Thanks and Regards.
-
@
QRegExpValidator("("|/)");
// or
QRegExpValidator("("|/){1}");
@ -
Already i had tried in this way
@QRegExpValidator("("|/)"); @and i failed because i can only enter either one of the characters in my line edit, also i want to enter other integer values (0-9 as double values).
Note: I want my Line Edit to behave something like this (eg. 70"1/2).
-
OK, you did not specify that in your initial post. Just follow the tutorial on "QRegExp":http://qt-project.org/doc/qt-4.8/qregexp.html, it's quite well written.
Don't expect regExps to be easy, though ;) Also, in Qt5, you can use QRegularExpression.
-
Yup... I know that QRegExp is not quite easy. anyways thanks for your suggestions.. :-)
Thanks & Regards
-
Just use:
@
QRegExpValidator("["/\d]");
@ -
Yup... I got it.... Thanks for your suggestion.... :-)