Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-29587

QWidget::keyReleaseEvent is called when typing the shortcut of a QAction

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • None
    • 5.0.0 RC 1, 5.0.0
    • Widgets: Main Window
    • None
    • Windows 7

    Description

      Say you have a QMainWindow subclass with a reimplemented keyPressEvent and keyReleaseEvent. If the window has an action with a QKeySequence shortcut, and you type that shortcut, keyPressEvent is not called. This is to be expected, since the QAction handles the event. However, keyReleaseEvent is called. This can result in unwanted keyReleaseEvents.

      #include <QtGui>
      #include <QtWidgets>
      
      class MainWindow : public QMainWindow
      {
      protected:
          void keyPressEvent(QKeyEvent *) {qDebug() << "pressed";}
          void keyReleaseEvent(QKeyEvent *) {qDebug() << "released";}
      };
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
          MainWindow window;
          QAction action(QString("Copy"), &window);
          action.setShortcut(QKeySequence::Copy);
          window.menuBar()->addAction(&action);
          window.show();
          return app.exec();
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            smd Jan Arve
            aprechtl Anthony Prechtl
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes