Sorting out qlineedit application technologies

Source: Internet
Author: User
Tags emit

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.