View Full Version : QSpinBox validator problem
batileon
9th July 2008, 10:26
In the past(QT3), I can use setValidator() for QSpinBox
for example,
QRegExpValidator *rv = new QRegExpValidator( rx, 0);
spinBox->setValidator( rv );
However I found that it is not possible to do so when porting to QT4.
Can anyone tell me what to do?
thanks
mchara
9th July 2008, 10:53
Hi,
one possibility is to
override
QValidator::State QAbstractSpinBox::validate ( QString & input, int & pos ) const [virtual]
and use validator inside.
Second approach is to get lineedit of a spinbox
QLineEdit * QAbstractSpinBox::lineEdit () const [protected]
an setValidator there
void QLineEdit::setValidator ( const QValidator * v )
axe
29th September 2011, 14:04
mchara
lineEdit() function is protected.
Do you mean it's not possible to set validator for spin box without inheriting it?
I'm already using QSpinBox class objects everywhere, how should I set validator for those objects?
wysota
29th September 2011, 15:54
If you're using Designer, you can use the "Promote to" tool available from context menu of items dropped on forms. If you're not using Designer then simply replace instances of QSpinBox with proper subclasses. However I would go for reimplementing validate() rather than trying tricks with spinbox's lineEdit.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.