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

QML Menus open to the wrong side in rtl layouts

    XMLWordPrintable

Details

    • User Story
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • None
    • None

    Description

      Basically: https://stackoverflow.com/questions/77997142/how-to-make-qml-menus-consider-layout-mirroring

      I'm developing a multi language application including languages that are rtl. When using the Menu control, they do not follow the LayoutMirroring.enabled setting in my top-level ApplicationWindow.

      In left-to-right mode everything looks alright

      but in right-to-left mode it doesn't work like it is intended. It still opens the menus to the right and also animates it that way.

      And this is what I would expect:

      Here's the code

      import QtQuick
      import QtQuick.Controls
      import QtQuick.Controls.Material
      
      ApplicationWindow {
          id: root
      
          property bool mirroringEnabled: false
      
          LayoutMirroring.enabled: mirroringEnabled
          LayoutMirroring.childrenInherit: true
      
          width: 640
          height: 480
          visible: true
      
          menuBar: MenuBar {
              Menu {
                  id: someMenu
                  title: qsTr("&File")
                  Action { text: qsTr("&New...") }
              }
              Menu {
                  title: qsTr("&Edit")
                  Action { text: qsTr("Cu&t") }
              }
              Menu {
                  title: qsTr("&Help")
                  Action { text: qsTr("&About") }
              }
          }
      
          Button {
              text: `mirror layout: ${root.mirroringEnabled}`
              anchors.centerIn: root.contentItem
      
              onClicked: {
                  console.log("---")
                  console.log("Before:     Menu mirrored:", someMenu.mirrored, "<-")
                  console.log("Before: Mirroring enabled:", root.mirroringEnabled)
                  root.mirroringEnabled = !root.mirroringEnabled
                  console.log("After:     Menu mirrored:", someMenu.mirrored, "<-")
                  console.log("After: Mirroring enabled:", root.mirroringEnabled)
              }
          }
      
      }
      

      and the code to get that thing running:

      from PySide6.QtCore import QUrl
      from PySide6.QtQml import QQmlApplicationEngine
      from PySide6.QtWidgets import QApplication
      
      if __name__ == '__main__':
          app = QApplication([])
          engine = QQmlApplicationEngine()
      
          engine.load(QUrl.fromLocalFile('window.qml'))
      
          if not engine.rootObjects():
              sys.exit(-1)
      
          app.exec()
      

      I'm working around it like this:

      Menu {
          id: root
      
          readonly property bool mMirrored: root.count > 0 && itemAt(0).mirrored
      
          x: mMirrored ? -width + parent.width : 0
      }
      

      But it'd be nice if it'd be fixed upstream

      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
            trin94 Elias Müller
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes