AnchorChanges
ImportStatement:
Properties
anchors
anchors.left : AnchorLine
anchors.right : AnchorLine
anchors.horizontalCenter : AnchorLine
anchors.top : AnchorLine
anchors.bottom : AnchorLine
anchors.verticalCenter : AnchorLine
anchors.baseline : AnchorLine
target : Item
DetailedDescription
AnchorChanges用来修改项目状态中的锚。它不能用来修改项目的边缘。项目的边缘可用PropertyChanges修改。
下面的例子中,我们用AnchorChanges改变了项目锚的顶部和底部,用PropertyChanges改变了项目顶部和底部的边缘。
import QtQuick 2.0
Rectangle {
id: window
width: 120; height: 120
color: "black"
Rectangle { id: myRect; width: 50; height: 50;color: "red" }
states: State {
name: "reanchored"
AnchorChanges {
target: myRect
anchors.top: window.top
anchors.bottom: window.bottom
}
PropertyChanges {
target: myRect
anchors.topMargin: 10
anchors.bottomMargin: 10
}
}
MouseArea { anchors.fill: parent; onClicked:window.state = "reanchored" }
}
AnchorChanges能用AnchorAnimation动画化。
//animate our anchor changes
Transition {
AnchorAnimation {}
}
改变锚的边缘可以用NumberAnimation动画化。
更多关于锚的信息,看Anchor Layouts。
PropertyDocumentation
anchors group
anchors.left : AnchorLine
anchors.right : AnchorLine
anchors.horizontalCenter : AnchorLine
anchors.top : AnchorLine
anchors.bottom : AnchorLine
anchors.verticalCenter : AnchorLine
anchors.baseline : AnchorLine
这些属性表示了各自实例的锚。我们可以分配未定义来重置锚。
AnchorChanges {
target: myItem
anchors.left:undefined
anchors.right: otherItem.right
}
target : Item
这个属性表示了锚变化用在那个实例上。