QLineEdit Validation for {[A-Z] [a-z][0-9]} text input
You can use setInputMask to specify the validation input mask, in your case you can use "N" or "n' to permit only characters in A-Z, a-z and 0-9 range. something like this:
lineEdit->setInputMask("nnnnnnnn;_"); // or NNNNNNNN;_
lineEdit->setCursorPosition(0);
You also can set QValidator
instance to your lineEdit
, via set setValidator
. This sets the lineEdit
to only accept input that the validator, will accept. This will work in conjunction with edit masks
If you only need to restrict the max permitted length of the line edit: use setMaxLength
lineEdit->setMaxLength(8);
hope this helps, regards
Surjya Narayana Padhi
I feel passionate to work in computer vision. It like a magic to me. Giving machines intelligence is so cool thing. I like to work various projects which are cool. Like to learn any technology on my way to accomplish a cool project. Exploring data,applying machine learning techniques for prediction or statistical methods to get insights is so awesome. Creating nice visualization using python is so nice. My hobby : Reading recent science news, Astrology, music
Updated on June 27, 2022Comments
-
Surjya Narayana Padhi almost 2 years
I want to accept a new username from the user in my application. I want the username string to contain only
A-Z
ora-z
or0-9
, and have a maxLength of 8. So I want to validate the input fromQLineEdit
. I went through the documentation but I am messed up with validators. How I can validate myQLineEdit
for this purpose?