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

Menu doesn't close when clicking outside window or into child window

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.5.3, 6.7.2, 6.8.0 Beta2
    • Quick: Controls 2
    • None
    • macOS, Windows

    Description

      Menu doesn't close when clicking outside window or into child window

      Code sample:

      import QtQuick
      import QtQuick.Controls
      
      Window {
          id: window
          width: 320
          height: 400
          visible: true
          title: 'Main window'
      
          Menu {
              id: menu
              MenuItem { text: 'Item1' }
              MenuItem { text: 'Item2' }
              MenuItem { text: 'Item3' }
          }
      
          TapHandler {
              acceptedButtons: Qt.RightButton
              onTapped: menu.open()
          }
      
          Window {
              width: 200
              height: 200
              visible: true
              title: 'Child window'
              x: window.x + window.width
              y: window.y + window.height - height
          }
      }
      

      Step to reproduce:
      1. Right click into "Main window" - menu opens
      2. Click outside the window or into "Child window"

      Actual results: menu doesn't close
      Expected results: menu should close

      Workaround:
      Just handle menu's active focus change

              onActiveFocusChanged: {
                  if (!activeFocus)
                      close()
              }
      

       But unfortunately this doesn't work in case when child window has flag Qt.WindowDoesNotAcceptFocus

      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
            studiosus Vladimir Belyavsky
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes