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

windows specific: QKeyEvent::key() returns wrong value for some keys when Ctrl is pressed (US keyboard layout)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • None
    • 4.6.2, 4.8.3, 5.0.0 Beta 2
    • Core: Event loop
    • None
    • Windows XP; US keyboard layout
    • 5055183bc5a8288976f58c65b52276ad17491cad 98b49f88fa1dfe593bf8e4291bd12419d47c26aa

      According to the document, QKeyEvent::key() should return platform independent key code value for the key pressed. but on windows, with US keyboard layout, it seems that the key is not correct when Shift is combined with Ctrl.
      For example,
      correct cases:

      • by pressing Shift+ '=' we get Qt::Key_Plus and modifier for Shift
      • by pressing Alt+Shift+ '=' we get Qt::Key_Plus and modifier for Shift+Alt

      wrong case:

      1. by pressing Ctrl+Shift+'=', we get '=' and modifier for Ctrl+Shift.

      On linux, it works fine.

      The following code can be used as test case:

      #include <QKeyEvent>
      #include <QApplication>
      #include <QWidget>
      
      class MainWin: public QWidget
      {
      public:
              MainWin(QWidget*p = NULL);
              ~MainWin(){};
              void keyPressEvent(QKeyEvent*);
      };
      
      MainWin::MainWin(QWidget*p ):QWidget(p)
      {
      }
      
      
      void MainWin::keyPressEvent(QKeyEvent*ev)
      {
              qWarning("%d, %d, %d, %08x", ev->key(), ev->nativeVirtualKey(), Qt::Key_Plus, (int)ev->modifiers());
              return QWidget::keyPressEvent(ev);
      }
      
      int main(int argc, char* argv[])
      {
              QApplication a(argc, argv);
              MainWin mw;
              mw.show();
              return a.exec();
      }
      

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

            owolff Oliver Wolff
            sanonymous Nokia Qt Support (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes