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

Enabling keyNavigation in Menu's contentItem causes MenuSeparators and hidden MenuItems to take keyboard focus

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.5.2
    • None
    • openSUSE Tumbleweed 20231001
    • Linux/X11

    Description

      See the following code

      import QtQuick
      import QtQuick.Controls
      ApplicationWindow {
          width: 800
          height: 600
          visible: true
          Button {
              text: "Open menu"
              onClicked: menu.open()
          }
          Menu {
              id: menu
              MenuItem { text: "Menu Item 1" }
              Action { text: "Action 1" }
              MenuSeparator {}
              MenuItem { text: "Menu Item 2" }
              Action { text: "Action 2" }
              MenuSeparator {}
              MenuItem { text: "Hidden menu item"; visible: false }
              MenuItem { text: "Disabled menu item"; enabled: false}
              MenuSeparator {}
              Menu { title: "Sub Menu" }
              contentItem: ListView {
                  implicitWidth: contentWidth
                  implicitHeight: contentHeight
                  model: menu.contentModel
                  keyNavigationWraps: true
                  keyNavigationEnabled: true
                  currentIndex: 0
              }
          }
      } 

      Run the code, click the button and start pressing the down key. You will notice that separators and the hidden menu item start grabbing keyboard focus.

      Also note that setting `keyNavigationEnabled: false` does not disable keyboard navigation.

      I need to override `contentItem` otherwise there is no way to enable keyboard navigation wrapping.

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            jackh Jack Hill
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes