ParentAnimation QML Type
以动画效果展示父级值的变更。更多...
| Import Statement: | import QtQuick |
| Inherits: |
属性
详细说明
ParentAnimation 用于为Item 的父节点变更添加动画效果。
例如,以下 `ParentChange ` 在被点击时,会将 `blueRect ` 更改为 `redRect ` 的子项。通过引入 `ParentAnimation`(其中定义了在过渡期间应用的 `NumberAnimation `),可确保该项在移动到新父项时动画效果流畅:
import QtQuick
Item {
width: 200; height: 100
Rectangle {
id: redRect
width: 100; height: 100
color: "red"
}
Rectangle {
id: blueRect
x: redRect.width
width: 50; height: 50
color: "blue"
states: State {
name: "reparented"
ParentChange { target: blueRect; parent: redRect; x: 10; y: 10 }
}
transitions: Transition {
ParentAnimation {
NumberAnimation { properties: "x,y"; duration: 1000 }
}
}
MouseArea { anchors.fill: parent; onClicked: blueRect.state = "reparented" }
}
}一个 ParentAnimation 可以包含任意数量的动画。这些动画将并行运行;若要顺序运行它们,请将它们定义在SequentialAnimation 中。
在某些情况下,例如在启用了裁剪功能的项目之间进行重新归属时,通过另一个未启用裁剪功能的项目来动画化父级变更会非常有用。可以通过via 属性设置此类项目。
ParentAnimation 通常在Transition 中与ParentChange 配合使用。以这种方式使用时,它会对状态变化期间发生的任何ParentChange 进行动画处理。可以通过使用target 属性设置特定的目标对象来覆盖此行为。
另请参阅 《Qt Quick 》中的“动画与过渡”以及《Qt Quick 示例——动画》。
属性文档
newParent : Item
要进行动画处理的新父元素。
如果ParentAnimation 是在Transition 内定义的,则此值默认为Transition 的结束状态中定义的值。
target : Item
要重新关联的对象。
在过渡效果中使用时,如果未指定目标,所有ParentChange 的实例都将由ParentAnimation 进行动画处理。
via : Item
要重新设置父级关系的对象。当旧父级和新父级均被裁剪时,这提供了一种实现无裁剪动画的方法。
ParentAnimation {
target: myItem
via: topLevelItem
// ...
}注意:此功能 仅在将ParentAnimation 与Transition 结合使用,并配合ParentChange 时有效。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.