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

QQC2 MenuBar::insertMenu doesn't operate as expected or consistently

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2, 6.7, 6.x
    • Quick: Controls 2
    • None
    • All

    Description

      Dynamically creating a Menu and inserting it into a MenuBar appears to be fundamentally broken. Doing so results in the position of the Menu (and indeed the ordering of the MenuBar as a whole) being somewhat random.

      Here is a simple test case:

      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.15
      
      ApplicationWindow
      {
          id: mainWindow
      
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          menuBar: MenuBar
          {
              id: mainMenuBar
      
              Menu { title: "Static 1" }
              Menu { title: "Static 2" }
          }
      
          Component { id: menuComponent; Menu {} }
      
          Button
          {
              anchors.centerIn: parent
              text: "Insert Menu At Start"
              onClicked: { mainMenuBar.insertMenu(0, menuComponent.createObject(mainMenuBar, {"title": "First"})); }
          }
      }
      

      If I click the button 4 times, I get the order seen in the attached screenshot; Static 2 First First Static 1 First First. I would expect to see First First First First Static 1 Static 2.

      Furthermore, I see the following in the application output:

      QQuickItem::stackBefore: Cannot stack MenuBarItem_QMLTYPE_1(0x55555569df20, parent=0x555555820730, geometry=104.797,0 62.4844x29) before MenuBarItem_QMLTYPE_1(0x55555569df20), which must be a sibling
      QQuickItem::stackBefore: Cannot stack MenuBarItem_QMLTYPE_1(0x555555b027c0, parent=0x555555820730, geometry=104.797,0 62.4844x29) before MenuBarItem_QMLTYPE_1(0x555555b027c0), which must be a sibling
      QQuickItem::stackBefore: Cannot stack MenuBarItem_QMLTYPE_1(0x5555558b2c20, parent=0x555555820730, geometry=124.969,0 42.3125x29) before MenuBarItem_QMLTYPE_1(0x5555558b2c20), which must be a sibling
      

      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
            timangus Tim Angus
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes