这是我尝试过的:
/* The way I want it:
* red
* blue green
* yellow
*/
import QtQuick 2.0
Item
{
Rectangle
{
id : one
height : 100
width : 100
color : "red"
anchors.leftMargin : 20
anchors.topMargin : 20
anchors.rightMargin : 20
anchors.bottomMargin : 20
}
Rectangle
{
id : two
height : 100
width : 100
color : "blue"
anchors.leftMargin : 20
anchors.topMargin : 20
anchors.rightMargin : 20
anchors.bottomMargin : 20
// On the top of blue rectangle there should be the red rectangle.
anchors.top : one.bottom
// And the blue rectangle should be on the bottom left of the red rectangle
anchors.right : one.left
}
Rectangle
{
id : three
height : 100
width : 100
color : "green"
anchors.leftMargin : 20
anchors.topMargin : 20
anchors.rightMargin : 20
anchors.bottomMargin : 20
// On the top of green rectangle there should be the red rectangle.
anchors.top : one.bottom
// And the green rectangle should be on the bottom right of the red rectangle
anchors.left : one.right
}
Rectangle
{
id : four
height : 100
width : 100
color : "yellow"
anchors.leftMargin : 20
anchors.topMargin : 20
anchors.rightMargin : 20
anchors.bottomMargin : 20
// On the top of yellow rectangle there should be the blue rectangle and green rectangle.
anchors.top : two.bottom
// And the yellow rectangle should be on the bottom right of the blue rectangle
anchors.left : two.right
// And the yellow rectangle should be on the bottom left of the green rectangle.
anchors.right : three.left
}
}
这就是我得到的:
在这里看不到蓝色矩形: