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

macOS: QKeySequence from string not working for arrow keys

XMLWordPrintable

    • macOS

      On macOS, if you use QKeyPressEvent, you will get "Num↑" etc. if you press an arrow key, using:

      QString keyName = QKeySequence(keyEvent->key() | keyEvent->modifiers()).toString(QKeySequence::NativeText);
      qDebug() << keyName; // Prints "Num↑", "Num↓", "Num←", "Num→" for the arrow keys

      But if you reverse this and try to get QKeySequence using the string, you'll always get Qt::Key_unknown for all 4 arrow keys ("Num↑", "Num↓", "Num←", "Num→").

      const QKeySequence seq(keyName);
      if (seq.count() >= 1)
          qDebug() << seq[0]; // prints 3355443 which is Qt::Key_unknown, for "Num↑", "Num↓", "Num←", "Num→"

      I would expect different numbers for the 4 keyNames.
      The keyEvent::key() for the arrow keys returns Qt::Key_Left, Qt::Key_Right, Qt::Key_Up and Qt::Key_Down.

      Since we are using non-commercial versions of Qt, please let me know if this was fixed in Qt 6. 

        1. image-2022-04-07-12-54-55-078.png
          450 kB
          Tor Arne Vestbø
        2. image-2022-04-07-13-06-00-504.png
          604 kB
          Tor Arne Vestbø
        For Gerrit Dashboard: QTBUG-99688
        # Subject Branch Project Status CR V

            vestbo Tor Arne Vestbø
            megamouse Patrick Waldner
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes