I’ve written a Qt GUI which contains some QSpinBoxes and QDoubleSpinBoxes, among other stuff. Everything works as intended, except for one thing: when I enter a number into the QSpinBoxes and finish the entry by pressing the “Enter” key, this also activates the first widget in the tab order: i.e. instead of just changing the value of my spin box, I’m also pressing the button at the top of my dialog – which I don’t want. How can I fix this? (Note that I need to press Enter for the new value to be accepted, because the spin boxes’ keyboard tracking is deactivated.)
EDIT: In case someone comes across a similar problem: http://developer.qt.nokia.com/doc/qt-4.8/eventsandfilters.html
I think what might be happening is the default button of a
QDialogis being pressed when you press Enter.If you are subclassing
QDialogyourself, then one of yourQPushButtons has it’s default property set to true. If you revert that to false, then the button will not react to the Enter key unless in focus. The disadvantage here, is that your dialog can’t be dismissed by pressing Enter, if you want to stick with the default values for example.