关于C#:Qml Grid,Column和RowLayout不适用于LayoutMirroring

Qml Grid, Column, and RowLayout does not work with LayoutMirroring

我正在编写一个qml应用程序,该应用程序应支持RTL和LTR语言,并且接口必须具有一定的灵活性,并且锚点可能无法产生良好的UI

所以我计划使用qml Grid,Column和RowLayout,它们可以正常工作,但是当我使用

时不会被镜像

1
2
LayoutMirroring.enabled: true
LayoutMirroring.childrenInherit: true

有什么方法可以将这些布局组件与LayoutMirroring.enabled一起使用:true
如果不是,如何为qml定位器(行,列和网格)设置宽度和高度以填充其边界项的宽度和高度


在Qt 5.2中,RowLayout,ColumnLayout和GridLayout具有layoutDirection属性以支持RTL布局


LayoutMirroring不适用于RowLayout,ColumnLayout或GridLayout。您可以改用Row [View],Column [View]或Grid [View]。有关更多信息,请参见http://qt-project.org/doc/qt-5.1/qtquick/qml-qtquick2-layoutmirroring.html。

以下是qml定位器的快速示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
            }
        }
    }
}

更改列数并添加或删除一些矩形,以查看它是否起作用。