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

Checkable Platform MenuItem can't be used like Controls MenuItem

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.11.0 Beta 2
    • 5.11
    • Quick: Controls 2
    • None
    • macOS
    • b4db69eee6dc2f381b24aa24586171dbaf8d116e

    Description

      This code works as expected:

      import QtQuick 2.9
      import QtQuick.Controls 2.3
      
      ApplicationWindow {
          id: root
          width: 600
          height: 600
          visible: true
      
          property bool foo: true
      
          Label {
              text: foo
              anchors.centerIn: parent
          }
      
          MenuBar {
              MenuBarItem {
                  objectName: "animationMenuBarItem"
                  focusPolicy: Qt.TabFocus
                  menu: Menu {
                      title: qsTr("Animation")
      
                      MenuItem {
                          objectName: "animationPlaybackMenuButton"
                          text: qsTr("Animation Playback")
                          checkable: true
                          checked: foo
                          onClicked: foo = checked
                      }
                  }
              }
          }
      }
      

      But with the equivalent Platform code, triggered() is emitted before checked is changed:

      import QtQuick 2.9
      import QtQuick.Controls 2.3
      import Qt.labs.platform 1.0 as Platform
      
      ApplicationWindow {
          id: root
          width: 600
          height: 600
          visible: true
      
          property bool foo: true
      
          Label {
              text: foo
              anchors.centerIn: parent
          }
      
          Platform.MenuBar {
              Platform.Menu {
                  id: animationMenu
                  objectName: "animationMenu"
                  title: qsTr("Animation")
      
                  Platform.MenuItem {
                      id: animationPlaybackMenuButton
                      objectName: "animationPlaybackMenuButton"
                      text: qsTr("Animation Playback")
                      checkable: true
                      checked: foo
                      onTriggered: foo = checked
                  }
              }
          }
      }
      

      I thought I could work around it by negating checked:

      onTriggered: foo = !checked
      

      but then the menu item's checked state is incorrect.

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            mitch_curtis Mitch Curtis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes