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

Using a shortcut ALT + some_key in a QMenu can leave the QMenuBar highlighted when releasing the keys, causing the focus to be lost.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.9.0 Alpha
    • 5.4.2, 5.5.0, 5.5.1, 5.6.0, 5.6.1, 5.7.0
    • Widgets: Main Window
    • None
    • All Windows
    • 9944a12a0f57087ea19ae428ffcd974ac0fed7bc

    Description

      Usually if someone presses the key combination it is pressed like this (for example Alt+Z):
      Push Alt -> Push Z -> Release Z -> Release Alt
      And the last two actions are almost simultaneous. This is the reason why sometimes the combination is press in this way:
      Push Alt -> Push Z -> Release Alt -> Release Z
      In this second case Editor is losing focus and it is impossible to continue typing ... you need to press Esc to continue typing. And this is VERY inconvenient because it happens not regularly!

      Try to press Alt+Z 10 times (for example in test app with code given below) and see how many times you will end up in top menu selected (and editor will lose focus).
      This behavior is not happening in native windows applications like office.

      Menu should be activated ONLY if single Alt is pressed
      Push Alt -> Release Alt

      Newly created Qt Widget application which shows the behavior:

      main.cpp
      #include <QApplication>
      #include <QMainWindow>
      #include <QMenuBar>
      #include <QPlainTextEdit>
      
      class Window : public QMainWindow {
       public:
        Window() {
          QPlainTextEdit *edit = new QPlainTextEdit;
          setCentralWidget(edit);
          QMenu *menu = menuBar()->addMenu("File");
          QAction *action = menu->addAction("Some Action");
          action->setShortcut(QKeySequence("Alt+Z"));
        }
      };
      
      int main(int argc, char *argv[]) {
          QApplication app(argc, argv);
      
          Window w; w.show();
      
          return app.exec();
      }
      

      Moreover the discussed behavior depends on existence of Action with this combination of keys which means that widgets were designed to behave in the right manner ... but adding of Action influences that.
      Try to press Alt+X 10 times in example app and you will never activate menu.

      P.S.
      Existence of QPlainTextEdit in the example app is not influencing the behavior so it can be commented:

      main.cpp
          //QPlainTextEdit *edit = new QPlainTextEdit;
          //setCentralWidget(edit);
      

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-46812
          # Subject Branch Project Status CR V

          Activity

            People

              Unassigned Unassigned
              progrev Prav Ogrev
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes