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

Non-Editable ComboBox wrongly propagates KeyEvent that has already been accepted

    XMLWordPrintable

Details

    • 3cbf7213d (dev), e3efbdb2a (6.5), 0ab180a3a (tqtc/lts-6.2)

    Description

      Code

      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.15
      import QtQuick.Layouts 1.15
      
      Window {
          width: 400
          height: 300
          visible: true
      
          function discardSpaceKey(keyEvent, source) {
              console.log(`Discarding [Space] in ${source}...`)
              keyEvent.accepted = true
          }
      
          ColumnLayout {
              anchors.fill: parent
      
              TextField {
                  id: textField
                  Layout.fillWidth: true
                  text: "TextField"
                  Keys.onSpacePressed: (event) => discardSpaceKey(event, "TextField")
              }
      
              ComboBox{
                  id: editableComboBox
                  Layout.fillWidth: true
                  editable: true
                  model: ["ComboBox:Editable", "Alpha", "Bravo", "Charlie"]
                  Keys.onSpacePressed: (event) => discardSpaceKey(event, "Editable ComboBox")
              }
      
              ComboBox{
                  id: nonEditableComboBox
                  Layout.fillWidth: true
                  editable: false
                  model: ["ComboBox:NonEditable", "Delta", "Echo", "Foxtrot"]
                  Keys.onSpacePressed: (event) => discardSpaceKey(event, "Non-Editable ComboBox")
              }
          }
      
          Component.onCompleted: textField.focus = true
      }
      

       

      Steps to reproduce

      1. Run the above code; textField should receive focus at startup
      2. Press [Space]
      3. Press [Tab] until editableComboBox receives focus
      4. Press [Space]
      5. Click the arrow indicator of editableComboBox to open its popup
      6. Hover the mouse cursor over "Bravo" and press [Space]
      7. Press [Tab] until nonEditableComboBox receives focus
      8. Press [Space]
      9. Click the arrow indicator of nonEditableComboBox to open its popup
      10. Hover the mouse cursor over "Echo" and press [Space]

       

      Actual outcomes

      • Step #2: Nothing happens (expected)
      • Step #4: Nothing happens (expected)
      • Step #6: Nothing happens (expected)
      • Step #8: The popup of nonEditableComboBox appears (not expected)
      • Step #10: The popup of nonEditableComboBox disappears and "Echo" is selected (not expected)

       

      Expected outcomes
      nonEditableComboBox should treat the [Space] key like how editableComboBox does.

      Attachments

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

        Activity

          People

            vhilshei Volker Hilsheimer
            skoh-qt Sze Howe Koh
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes