Control the input range of qlineedit
1. Use a regular expression to check the input range of qlineedit (the Code is as follows ):
# Include <qvalidator. h>
# Include <qlineedit. h>
Qlineedit * lineedit = new qlineedit (this );
Qregexp Regexp ("[A-Za-Z] [1-9] [0-9] {0, 2 }"); // ^ [1-9] [0-9] * $ and ^ [1-9] {1} [/d] * $
// The regular expression above indicates that only positive integers greater than 0 can be entered.
Lineedit-> setvalidator (New qregexpvalidator (Regexp, this ));
##### Or use this
Qlineedit: add only letters and numbers to favorites
Qregexp regx ("[a-zA-Z0-9] + $ ");
Qvalidator * validator = new qregexpvalidator (regx, lined );
UI-> lined-> setvalidator (validator );
2. Use the qintvalidator integer verification control to control the input range of qlineedit (the Code is as follows ):
# Include <qvalidator. h>
# Include <qlineedit. h>
Qvalidator * validator = new qintvalidator (100,999, this );
Qlineedit * edit = new qlineedit (this );
// Only allow Edit to input an integer between 100 and 999
Edit-> setvalidator (validator );
Lineedit = qlineedit () instantiate an input box
Lineedit = setreadonly (true) # Set to read-only
Lineedit. setdragenabled (true) # Set to accept drag and drop
Lineedit. setmaxlength (5) # set the maximum length
Lineedit. selectall () # select all
Lineedit. setfocus () # Get focus
Lineedit. setinputmask ("dx") # You must enter two characters to modify the input box.
Punctuationre = qregexp (R "[,;:.]") # obtain a Regexp object. The following verification is available:
Lineedit. setvalidator (qregexpvalidator (qregexp (R "[0-9] +"), Self) # set verification to verify user input
Lineedit. emit (signal ('textchanged (qstring) ') signal (when set to read-only, it seems that no specific test is available)
Lineedit. emit (signal (textedited (qstring) ') sends a signal if it is set to verify that the signal can be issued only after it passes verification (when set to read-only, it seems that no specific test is available)