2017-06-15 7 views
1

Ich mag mein Demo-Layout festgelegt ist von rechts nach links, und ich setze diese in Hauptfunktion, wie folgt aus:Warum setLayoutDirection funktioniert nicht in meiner Qt Quick-Demo?

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(); 
} 

Hier meine qml Datei ist:

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 
       } 
      } 
     } 
    } 
} 

jedoch das Layout-Ergebnis noch links ist nach rechts: enter image description here

Wie kann ich die reale RTL Layout bekommen, sind alle Komponenten von rechts nach links, gehören der Text, so wie diese: enter image description here

Antwort

0

Right-to-left User Interfaces besagt, dass Sie die LayoutMirroring angefügten Eigenschaften verwenden sollten. Nehmen wir das Beispiel von dieser Seite:

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 
       } 
      } 
     } 
    } 
} 
+0

die LayoutMirroring existiert nicht in dem Rechteck, aber nicht in Fenster ...... – AdvancingEnemy

+0

Sie können es viel überall hinstellen recht, denke ich. In Ihrem Fall, setzen Sie einfach diese beiden Zeilen unter 'id: root'. – Mitch

+0

Holen Sie es! Danke mein Freund. Warum funktioniert LayoutMirroring nicht in Slider? – AdvancingEnemy

Verwandte Themen