C
AnchorChanges QML Type
指定如何在特定状态下更改项目锚点。更多...
| Import Statement: | import QtQuick |
| Since: | Qt Quick Ultralite 1.0 |
属性
- anchors
- anchors.baseline : AnchorLine
- anchors.bottom : AnchorLine
- anchors.horizontalCenter : AnchorLine
- anchors.left : AnchorLine
- anchors.right : AnchorLine
- anchors.top : AnchorLine
- anchors.verticalCenter : AnchorLine
- target : Item
详细说明
AnchorChanges 类型用于修改State 中某项的锚点。
AnchorChanges 无法用于修改项目的边距。若需修改边距,请改用 `PropertyChanges `。
在下面的示例中,我们使用 AnchorChanges 更改项目的顶部和底部锚点,并使用PropertyChanges 更改顶部和底部锚点的边距:
import QtQuick 2.15 Rectangle { id: window width: 120; height: 120 color: "black" Rectangle { id: anchorRectStart; x: 60; y: 60; height: 60; width: 60; color: "yellow"} Rectangle { id: anchorRectEnd; x: 0; y: 0; height: 60; width: 60; color: "blue"} Rectangle { id: myRect; color: "red" anchors { top: anchorRectStart.top bottom: anchorRectStart.bottom left: anchorRectStart.left right: anchorRectStart.right topMargin: 10 bottomMargin: 10 leftMargin: 10 rightMargin: 10 } } states: State { name: "reanchored" AnchorChanges { target: myRect anchors { top: anchorRectEnd.top bottom: anchorRectEnd.bottom left: anchorRectEnd.left right: anchorRectEnd.right } } PropertyChanges { target: myRect anchors { topMargin: 20 bottomMargin: 20 leftMargin: 20 rightMargin: 20 } } } MouseArea { anchors.fill: parent; onClicked: window.state = "reanchored" } }

锚点边距的更改可通过 `NumberAnimation` 实现动画效果。
有关锚点的更多信息,请参阅《锚点布局》。
属性文档
anchors group
anchors.baseline : AnchorLine
anchors.bottom : AnchorLine
anchors.horizontalCenter : AnchorLine
anchors.left : AnchorLine
anchors.right : AnchorLine
anchors.top : AnchorLine
anchors.verticalCenter : AnchorLine
这些属性会更改该项目的相应锚点。
target : Item
该属性存储将应用锚点更改的Item 。
在某些 Qt 许可下可用。
了解更多信息。