我正在开发一个多语言应用程序,包括rtl种语言.使用Menu控件时,它们不遵循我的顶级ApplicationWindow中的LayoutMirroring.enabled设置.

在从左到右模式下,一切看起来都很正常:

enter image description here

但在从右到左的模式下,它并不像预期的那样工作.它仍然会打开右侧的菜单,并以此方式为其设置动画.

enter image description here

And this is what I would expect: enter image description here

代码如下:

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)
        }
    }

}

以及让它运行的代码:

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()

我试过的东西:

  • 在菜单上显式设置parent属性会使其向正确的一侧打开,但会完全扰乱定位
  • QApplicationQGuiApplication也不行

如有任何帮助,将不胜感激!提前感谢您:)

推荐答案

我在他们的虫子追踪器里打开了a bug个.在问题得到解决之前,我将基于@SMR的 idea 使用我的变通方法:

Menu {

    readonly property bool mMirrored: root.count > 0 && itemAt(0).mirrored

    x: mMirrored ? -width + parent.width : 0
}

因此,因为mirrored属性在菜单本身上不起作用,所以我们从第一项开始查找它:)

Python相关问答推荐

使用SciPy进行曲线匹配未能给出正确的匹配

从numpy数组和参数创建收件箱

发生异常:TclMessage命令名称无效.!listbox"

如何过滤包含2个指定子字符串的收件箱列名?

Telethon加入私有频道

numpy卷积与有效

关于Python异步编程的问题和使用await/await def关键字

把一个pandas文件夹从juyter笔记本放到堆栈溢出问题中的最快方法?

重置PD帧中的值

当单元测试失败时,是否有一个惯例会抛出许多类似的错误消息?

用两个字符串构建回文

Python 3试图访问在线程调用中实例化的类的对象

Python协议不兼容警告

如何根据一定条件生成段id

有了Gekko,可以创建子模型或将模型合并在一起吗?

类型对象';敌人';没有属性';损害';

正在try 让Python读取特定的CSV文件

.awk文件可以使用子进程执行吗?

对于数组中的所有元素,Pandas SELECT行都具有值

使用Django标签显示信息