我正在编写一个应该支持 RTL 和 LTR 语言的 qml 应用程序,界面需要有一定的灵 active , anchor 可能不会产生好的 UI
所以我计划使用 qml Grid、Column 和 RowLayout,它们运行良好但在我使用时没有得到镜像
LayoutMirroring.enabled: true
LayoutMirroring.childrenInherit: true
有什么方法可以通过 LayoutMirroring.enabled: true 使用这些布局组件 如果不是,如何设置 qml 定位器(行、列和网格)的宽度和高度以填充其边界项的宽度和高度
最佳答案
LayoutMirroring 不适用于 RowLayout、ColumnLayout 或 GridLayout。您可以改用 Row[View]、Column[View] 或 Grid[View]。参见 http://qt-project.org/doc/qt-5.1/qtquick/qml-qtquick2-layoutmirroring.html获取更多信息。
这是一个 qml 定位器的简单示例:
Rectangle {
width: 640
height: 480
color: "#303030"
Rectangle {
width: parent.width / 1.1
height: parent.height / 1.1
anchors.centerIn: parent
color: "white"
Grid {
id: grid
anchors.fill: parent
columns: 2
spacing: 6
columnSpacing: spacing
rowSpacing: spacing
property int rowCount: Math.ceil(visibleChildren.length / columns)
property real cellWidth: (width - (columns - 1) * columnSpacing) / columns
property real cellHeight: (height - (rowCount - 1) * rowSpacing) / rowCount
Rectangle {
color: "#aa6666"
width: grid.cellWidth
height: grid.cellHeight
}
Rectangle {
color: "#aaaa66"
width: grid.cellWidth
height: grid.cellHeight
}
Rectangle {
color: "#9999aa"
width: grid.cellWidth
height: grid.cellHeight
}
Rectangle {
color: "#6666aa"
width: grid.cellWidth
height: grid.cellHeight
}
}
}
}
更改列数并添加或删除一些矩形,看看它是否有效。
关于c++ - Qml Grid、Column 和 RowLayout 不适用于 LayoutMirroring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18376356/