c++ - Qml Grid、Column 和 RowLayout 不适用于 LayoutMirroring

标签 c++ qt qml

我正在编写一个应该支持 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/

相关文章:

c++ - 如何缓存从MySQL数据库创建的对象

C++ MFC改变单选框的背景颜色

android - "<FlexLexer.h> not found",仅在 C++ 模式下发生

c++ - QT C++ - OpenSSL AES - EVP.h

qt - 如何创建将QAbstractItemModel的节点展平到PySide中的列表的代理模型?

c++ - Qt 图表 (QML) 日期时间轴中缺少二月

c++ - 查找图中两个节点之间的所有路径

qt - 如何使用 cmake 包含 qt 目录和库

c++ - 在 C++ 中更改 QML font.pointSize

c++ - 在 main.cpp 之外使用 QQuickView