I want to have a QLineEdit
that accepts only a character or digit . Is there a possibility to set it like in html an input to have a maxlength
? I mean to do this from the constructor of QLineEdit
?
I don't need something complicated ...
I want to have a QLineEdit
that accepts only a character or digit . Is there a possibility to set it like in html an input to have a maxlength
? I mean to do this from the constructor of QLineEdit
?
I don't need something complicated ...
Everything is exactly like you wanted it to be. QLineEdit
has the maxLength
property. You set it either using the property system, or using the setter method:
QLineEdit le;
le.setMaxLength(1);
That's it.
I don't need someting complicated ...
Unfortunately, it's couldn't be called easy solution, but you should be advised about QRegExpValidator.
Usage example:
#include <QRegExpValidaor>
#include <QLineEdit>
...
...
QRegExp rx ("\\w");
QRegExpValidator * v = new QRegExpValidator (rx, this);
QLineEdit * le = new QLineEdit (this);
le->setValidator (v);
Here is the alternate way to limit line edit input to one character/digit:
QLineEdit le;
le.setInputMask("N");
le.show();
For more details on input mask usage refer to the Qt documentation.