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

Action in Menu: Won't close menu when action results in disabling itself

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 5.11.0
    • Quick: Controls 2
    • None

    Description

      A Menu won't close if a MenuItem references an action that disables itself on trigger.

      Performing the action directly in the MenuItem works as expected.

      import QtQuick 2.11
      import QtQuick.Window 2.11
      import QtQuick.Controls 2.3
      
      Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
      
        property int actionCount: 1
        property int menuItemCount: 1
      
        Action {
          id: action1
          text: "Action (will not close menu)"
          onTriggered: { actionCount--; console.log("Triggered Action") }
          enabled: actionCount > 0
        }
      
        Button {
          onClicked: menu.popup()
      
          Menu {
            id: menu
            MenuItem {
              action: action1
            }
            MenuItem {
              text: "MenuItem (will close menu)"
              onTriggered: { menuItemCount--; console.log("Triggered MenuItem"); }
              enabled: menuItemCount > 0
            }
          }
        }
      }
      

      Attachments

        Issue Links

          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
              njeisecke Nils Jeisecke
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes