PDA

View Full Version : Set maximum input length in spinbox?



hakermania
23rd December 2010, 20:49
I have a Spinbox. Its maximum value is 99, although this doesn't avoids the user to input e.g.
000000000000000000000000000000000000099
this is quite weird :/
How can i change the max input length of the spinbox? I found nothing from the properties menu :)
thx for any answer!:o

wysota
23rd December 2010, 23:54
I have a Spinbox. Its maximum value is 99, although this doesn't avoids the user to input e.g.
000000000000000000000000000000000000099
this is quite weird :/
I'd say 0000000000000000099 is exactly 99 which is in the bounds specified by the minimum and maximum value allowed.


How can i change the max input length of the spinbox? I found nothing from the properties menu :)
thx for any answer!:o
Reimplement validate() and/or fixup(). The former should be quite easy:

QValidator::State MySpinBox::validate( QString &text, int pos) const {
if(text.size()>2) return QValidator::Invalid;
return QSpinBox::validate(text, pos);
}