anchors布局
import QtQuick 2.2
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Rectangle {
width: 300;
height: 200;
color: "blue";
Rectangle {
id: rectl;
anchors.left: parent.left;
anchors.leftMargin: 20;
anchors.top: parent.top;
anchors.topMargin: 20;
width: 120;
height: 120;
gradient: Gradient {
GradientStop {position: 0.0;color: "#202020";}
GradientStop {position: 1.0;color: "#A0A0A0";}
}
}
Rectangle {
anchors.left: rectl.right;
anchors.leftMargin: 20;
anchors.top: rectl.top;
anchors.topMargin: 20;
width: 120;
height: 120;
rotation: 90;
gradient: Gradient {
GradientStop {position: 0.0;color: "#202020";}
GradientStop {position: 1.0;color: "#A0A0A0";}
}
}
}
}
运行结果如下