PDA

View Full Version : QLineEdit



bismitapadhy
11th August 2009, 06:24
I created a QLineEdit.I set inputmask as - 9.
If user is typing any other character other than digit QLineEdit text should not change. How can i do this.

addu
11th August 2009, 06:31
use validator

Thanks

Yuvaraj R

yogeshgokul
11th August 2009, 06:32
Try:

lineEdit->setInputMask("9999");//Will let you enter 4 digits

faldzip
11th August 2009, 08:24
QValidator is a better way than input mask. There are currently 3 validators prepared in Qt: QDoubleValidator, QIntValidator, QRegExpValidator.

If you want to validate as the input string is an int you can do it like this (from Qt Assistant):


QValidator *validator = new QIntValidator(100, 999, this);
QLineEdit *edit = new QLineEdit(this);

// the edit lineedit will only accept integers between 100 and 999
edit->setValidator(validator);

If you want some reg exp validating than:


QRegExp rx("[1-9]\\d{0,3}");
QValidator *validator = new QRegExpValidator(rx, this);
QLineEdit *edit = new QLineEdit(this);
edit->setValidator(validator);

will allow you to input numbers between 1 and 9999;