There is no setValidator for QSpinBox like as for QLineEdit.
I want to restrict the user's input to clicking up and down arrows only,
and not allow user to type a value into the spin box's line editor.
How to do ?
S.O.S
There is no setValidator for QSpinBox like as for QLineEdit.
I want to restrict the user's input to clicking up and down arrows only,
and not allow user to type a value into the spin box's line editor.
How to do ?
S.O.S
You can subclass QSpinBox, and reimplement keyPressEvent(QKeyEvent *event).
Use QKeyEvent::ignore() to ignore the event.
Or alternatively you can use event filters
I'm not really clear on how to do it exactly? where can i get help or some sample code?
You create a new class based on QSpinBox. For example:
Qt Code:
#include <QSpinBox> #include <QKeyEvent> { public: protected: // reimplement keyPressEvent { event->ignore(); } };To copy to clipboard, switch view to plain text mode
Last edited by saa7_go; 31st August 2010 at 07:20. Reason: updated contents
babygal (31st August 2010)
I realize this is an old thread, but another option is to make the QLineEdit with in the spin box read only.
Qt Code:
{ Q_OBJECT public: { lineEdit()->setReadOnly (true); } }; { Q_OBJECT public: { lineEdit()->setReadOnly (true); } };To copy to clipboard, switch view to plain text mode
Subclassing is unnecessary. QAbstractSpinBox, from which other spin box classes are derived, has a QAbstractSpinBox::setReadOnly() method which accomplishes what the OP wanted.
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
Bookmarks