Column是qml中的一個定位器,自動垂直排列子項,所需要設置的屬性相對比較少。
Rectangle{
anchors.fill: parent
color: "black"
Column{ //垂直佈局子對象
y:10
spacing: 20 //相鄰項的間隔
anchors.horizontalCenter: parent.horizontalCenter
Rectangle{
id:rec_1
height: 100
width: 100
radius: 5
color: "red"
}
Rectangle{
id:rec_2
height: 100
width: 100
radius: 5
color: "blue"
}
Rectangle{
id:rec_3
height: 100
width: 100
radius: 5
color: "yellow"
}
move: Transition { //移除過度
NumberAnimation {
properties:"y";
duration: 1000
}
}
//例子中當第二個的visible爲false時,執行動畫第三個矩形往上移動
//反之,當第二個由不可見變可見的時候,第三個往下移動執行動畫
add:Transition { //增加子對象的時候執行的動畫
NumberAnimation {
properties:"y";
duration: 1000
} //剛開始進入時慢慢從上往下滑,而不是一進入就顯示
}
}
MouseArea{
anchors.fill: parent
onClicked: {rec_2.visible = !rec_2.visible}
}
}