Qml Grid,Column和RowLayout不适用于LayoutMirroring

时间:2013-08-22 09:20:26

标签: c++ qt qml

我正在编写一个应该支持RTL和LTR语言的qml应用程序,并且界面需要有些灵活,并且锚点可能无法生成良好的UI

所以我计划使用qml Grid,Column和RowLayout,它们运行良好但在我使用时没有镜像

LayoutMirroring.enabled: true
LayoutMirroring.childrenInherit: true

有没有办法将这些布局组件用于 LayoutMirroring.enabled:true 如果不是如何设置qml定位器(行,列和网格)的宽度和高度来填充其边界项目的宽度和高度

2 个答案:

答案 0 :(得分:1)

LayoutMirroring不适用于RowLayout,ColumnLayout或GridLayout。您可以使用行[查看],列[查看]或网格[查看]。有关详细信息,请参阅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
            }
        }
    }
}

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

答案 1 :(得分:1)

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