我正在开发一个多语言应用程序,包括rtl种语言.使用Menu控件时,它们不遵循我的顶级ApplicationWindow中的LayoutMirroring.enabled
设置.
在从左到右模式下,一切看起来都很正常:
但在从右到左的模式下,它并不像预期的那样工作.它仍然会打开右侧的菜单,并以此方式为其设置动画.
And this is what I would expect:
代码如下:
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
属性会使其向正确的一侧打开,但会完全扰乱定位 - 从
QApplication
转QGuiApplication
也不行
如有任何帮助,将不胜感激!提前感谢您:)