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

Checkable Platform MenuItem can't be used like Controls MenuItem

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.11
    • Fix Version/s: 5.11.0 Beta 2
    • Component/s: Quick: Controls 2
    • Labels:
      None
    • Environment:
      macOS
    • Commits:
      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

            Assignee:
            Unassigned Unassigned
            Reporter:
            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