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

macOS: [Enter] key in TextField generates Qt.Key_Return instead of Qt.KeyEnter

    XMLWordPrintable

Details

    • macOS
    • 6767ac20c9 (qt/qtbase/dev) 6767ac20c9 (qt/tqtc-qtbase/dev) d7c33f16d9 (qt/tqtc-qtbase/6.2) 1311870125 (qt/qtbase/6.4) 1311870125 (qt/tqtc-qtbase/6.4) ab6721947c (qt/qtbase/6.3) ab6721947c (qt/tqtc-qtbase/6.3)

    Description

      Code

      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.15
      
      ApplicationWindow {
          id: root
          width: 200
          height: 150
          visible: true
      
          Column {
              anchors.fill: parent
      
              Frame {
                  focus: true
                  Keys.onPressed: (event) => {
                      console.log( "[Frame.Keys.onPressed]", "Key: 0x"+event.key.toString(16), "Modifiers: 0x"+event.modifiers.toString(16) )
                      event.accepted = true;
                  }
              }
      
              TextField {
                  placeholderText: "Click here to focus"
                  Keys.onPressed: (event) => {
                      console.log( "[TextField.Keys.onPressed]", "Key: 0x"+event.key.toString(16), "Modifiers: 0x"+event.modifiers.toString(16) )
                  }
              }
          }
      
          Component.onCompleted: {
              console.log( "The value of Qt.Key_Return     is 0x" + Number(Qt.Key_Return).toString(16) );
              console.log( "The value of Qt.Key_Enter      is 0x" + Number(Qt.Key_Enter).toString(16) );
              console.log( "The value of Qt.KeypadModifier is 0x" + Number(Qt.KeypadModifier).toString(16) );
          }
      }
      
      

       

      Steps to reproduce

      1. Run the code above. It will automatically force active focus on the Frame.
      2. Press [Return] (on the main keyboard)
      3. Press [Enter] (on the keypad)
      4. Press [Fn]+[Return]
      5. Click on the TextField to move active focus to the TextField.
      6. Repeat steps #2-#4 while the TextField has active focus.

      Note: For Step #4, [Fn]+[Return] is supposed to produce [Enter], according to https://apple.stackexchange.com/questions/47565/return-vs-enter

       

      Clarification

      qml: The value of Qt.Key_Return     is 0x1000004
      qml: The value of Qt.Key_Enter      is 0x1000005
      qml: The value of Qt.KeypadModifier is 0x20000000

       

      Results
      The value of event.key matches the pressed key when the Frame had active focus. However, when the TextField had active focus, event.key has the wrong value on macOS:

       

        QML output on Windows (all correct) QML output on macOS (TextField wrong)
      Step #2 on Frame [Frame.Keys.onPressed] Key: 0x1000004 Modifiers: 0x0 [Frame.Keys.onPressed] Key: 0x1000004 Modifiers: 0x0
      Step #3 on Frame [Frame.Keys.onPressed] Key: 0x1000005 Modifiers: 0x20000000 [Frame.Keys.onPressed] Key: 0x1000005 Modifiers: 0x20000000
      Step #4 on Frame (N/A) [Frame.Keys.onPressed] Key: 0x1000005 Modifiers: 0x20000000
      Step #2 on TextField [TextField.Keys.onPressed] Key: 0x1000004 Modifiers: 0x0 [TextField.Keys.onPressed] Key: 0x1000004 Modifiers: 0x0
      Step #3 on TextField [TextField.Keys.onPressed] Key: 0x1000005 Modifiers: 0x20000000 [TextField.Keys.onPressed] Key: 0x1000004 Modifiers: 0x20000000
      Step #4 on TextField (N/A) [TextField.Keys.onPressed] Key: 0x1000004 Modifiers: 0x20000000

      Attachments

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

        Activity

          People

            vestbo Tor Arne Vestbø
            skoh-qt Sze Howe Koh
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews