PDA

View Full Version : QLineEdit validator



pobere
5th November 2011, 09:18
Hi,

in a constructor of a class that inherits QLineEdit I have the following:


setInputMask("99:99");
QRegExp regexp("^([0-1][0-9]|[2][0-3]):([0-5][0-9])$");
QRegExpValidator *validator = new QRegExpValidator(regexp, this);
setValidator(validator);


This helps me to display and edit the time.

The validator works fine and also the input mask.The only problem is that:
the cursor can be moved at the position 5, and here is no char to change!
But we have in the mask only 5 chars, and the maximum position could be 4!

How can I get rid of such an annoying thing. :)


thanks.

Lykurg
5th November 2011, 10:02
Maybe QLineEdit::setMaxLength() could help you.

pobere
5th November 2011, 10:16
Nope, it doesn't. :(

If the line edit has an input mask, the mask defines the maximum string length.
The max length should be already set to 5 (in my case) by the mask...

I think, the validator should also validate the cursor position ... but it doesn't only for the last position (which is not valid).