QAction Qt::Key_Return shortcut is triggered by user entering values in GUI
I have an issue with associating a shotcut to a QAction. After mapping Enter to an action like this: @myAction->setShortcut(Qt::Key_Return);@ This action is triggered when I type a value in a QSpinBox and then press enter. I was expecting the spinbox to "accept" the event, so it's not caught by the mainwindow.
I've seen that I can add a context to my shortcut, I tried all values but this does not solve my issue.
Thanks a lot for your help.
EDIT: found someone with the same question but no answer :( http://lists.qt.nokia.com/pipermail/qt-interest/2009-July/010340.html
Hi. Try next in you MainWindow:
QAction* action1 = new QAction(this);
action1->setShortcut(QKeySequence(tr("Alt+F"))); // Or whatever you need
connect(action1, SIGNAL(triggered()), this, SLOT(action1Triggered()));
I don't understand why your code would solve my issue? This is more or less what I'm already doing.
Could you explain it? Thanks a lot
To process key-strokes in QLineeEdit you should override virtual function
virtual void keyReleaseEvent(QKeyEvent *event)
virtual void keyPressedEvent(QKeyEvent *event)
- my example adds global shortcut to main window
- you can try to install an event filter to QLineEdit - call
I would like to avoid subclassing all the standard widgets that do not accept and consume the Enter pressed event.