为什么setLayoutDirection没有';在我的Qt快速演示中不起作用?

为什么setLayoutDirection没有';在我的Qt快速演示中不起作用?,qt,qml,Qt,Qml,我想将我的演示布局设置为从右到左,我在主功能中设置如下: int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); app.setLayoutDirection(Qt::RightToLeft) return app.

我想将我的演示布局设置为从右到左,我在主功能中设置如下:

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    app.setLayoutDirection(Qt::RightToLeft)
    return app.exec();
}
这是我的qml文件:

import QtQuick 2.6
import QtQuick.Window 2.2

Window {
    visible: true
    width: 640
    height: 480
    id:root
    Row {
        spacing: 20
        Repeater {
            model: 5
            Rectangle {
                color: "red"
                opacity: (5 - index) / 5
                width: 70; height: 30

                Text {
                    text: index + 1+" hello"
                    width:parent.width
                }
            }
        }
    }
}
但是,布局结果仍然是从左到右:

如何获得真正的RTL布局,所有组件都是从右到左,包括文本,如下所示:

说您应该使用附加的属性。以该页中的示例为例:

import QtQuick 2.0

Rectangle {
    LayoutMirroring.enabled: true
    LayoutMirroring.childrenInherit: true

    width: 300; height: 50
    color: "yellow"
    border.width: 1

    Row {
        anchors { left: parent.left; margins: 5 }
        y: 5; spacing: 5

        Repeater {
            model: 5

            Rectangle {
                color: "red"
                opacity: (5 - index) / 5
                width: 40; height: 40

                Text {
                    text: index + 1
                    anchors.centerIn: parent
                }
            }
        }
    }
}

我想你几乎可以把它放在任何地方。在您的情况下,只需将这两行放在
id:root
下面即可!谢谢,我的朋友。顺便问一下,为什么LayoutMirroring在Slider中不起作用?不用担心。:)控制1还是控制2?它应该在控件2中工作,但我不确定控件1的状态是什么。