PropertyAnimation
一、描述
PropertyAnimation 提供了一种对属性值的更改进行动画处理的方法。继承自 Animation。
二、属性成员
1、properties : string
property : string
target : Object
targets : list<Object>
这些属性用作一组来确定应该动画化哪些属性。单数和复数形式在功能上是相同的。
只设置一个对象/属性时这两行的意思是一样的:
NumberAnimation { target: theItem; property: "x"; to: 500 }
NumberAnimation { targets: theItem; properties: "x"; to: 500 }
设置多个目标:
NumberAnimation { targets: [itemA, itemB]; properties: "x"; to: 500 }
2、duration : int
此属性保存动画的持续时间,以毫秒为单位。默认值为 250。
3、曲线组
easing.amplitude : real 缓和曲线幅度
easing.overshoot : real 缓和曲线过冲
easing.period : real 缓和曲线周期
easing.type : enumeration 缓和曲线类型,默认为Easing.Linear。
easing.bezierCurve : list<real> 此属性是一个列表<real>,包含定义从 0,0 到 1,1 的曲线的三个点组 - control1, control2, end point: [cx1, cy1, cx2, cy2, endx, endy]。 最后一点必须是 1,1。
4、exclude : list<Object>
此属性保存不受此动画影响的项目。
5、from : variant
此属性保存动画的起始值。
如果 PropertyAnimation 是在 Transition 或 Behavior 中定义的,则该值默认为 Transition 开始状态中定义的值,或触发 Behavior 时属性的当前值。
6、to : variant
此属性保存动画的结束值。
如果 PropertyAnimation 是在 Transition 或 Behavior 中定义的,则此值默认为在 Transition 的结束状态中定义的值,或触发 Behavior 的属性更改的值。
PropertyChanges
一、描述
PropertyChanges 用于定义状态中的属性值或绑定。这使项目的属性值可以在状态变化时更改。
import QtQuick 2.9
import QtQuick.Window 2.2
Window
{
visible: true
color: "black"
width: 300
height: 300
Item
{
id: container
anchors.fill: parent
Rectangle
{
id: rect
width: 100
height: 100
color: "red"
MouseArea
{
id: mouseArea
anchors.fill: parent
}
states: State
{
name: "resized"
when: mouseArea.pressed
PropertyChanges { target: rect; color: "yellow"; height: container.height }
}
}
}
}
PropertyChanges 对象还可以覆盖对象的默认信号处理程序以实现特定于新状态的信号处理程序:
PropertyChanges
{
target: myMouseArea
onClicked: doSomethingDifferent()
}
注意:PropertyChanges 可用于更改锚点边距,但不能用于更改其他锚点值(可使用 AnchorChanges)。 同样,要更改 Item 的父值,请改用 ParentChange。
重置属性值
undefined 值可用于重置状态的属性值。在下面的示例中,当 myText 更改为更宽的文本状态时,它的 width 属性被重置,赋予文本自然宽度并在一行中显示整个字符串。
Rectangle
{
width: 300; height: 200
Text
{
id: myText
width: 50
wrapMode: Text.WordWrap
text: "长度超过 50 像素的文本字符串"
states: State
{
name: "widerText"
PropertyChanges { target: myText; width: undefined }
}
}
MouseArea
{
anchors.fill: parent
onClicked: myText.state = "widerText"
}
}
Transitions 中的即时属性变化
当 Transitions 用于动画状态更改时,它们将属性从当前状态中的值动画化到新状态中定义的值(由 PropertyChanges 对象定义)。 但是,有时需要在 Transition 期间立即设置属性值,而不需要动画;在这些情况下,PropertyAction 类型可用于强制立即更改属性。
二、属性成员
1、explicit : bool
默认为false。如果显式设置为 true,则任何潜在的绑定都将被解释为进入状态时发生的一次性赋值。
2、restoreEntryValues : bool
此属性保存在离开状态时是否应恢复先前的值。默认值是true。
将此值设置为 false 会创建一个对属性值具有永久影响的临时状态。
3、target : Object
此属性保存包含要更改的属性的对象。
PropertyAction
一、描述
PropertyAction 用于指定动画期间的属性立即更改,即属性更改不使用动画的。
例如,这是一个 SequentialAnimation,它将图像的不透明度属性设置为 0.5,为图像的宽度设置动画,然后将不透明度设置回 1:
SequentialAnimation
{
PropertyAction { target: img; property: "opacity"; value: .5 }
NumberAnimation { target: img; property: "width"; to: 300; duration: 1000 }
PropertyAction { target: img; property: "opacity"; value: 1 }
}
二、属性成员
1、properties : string
property : string
target : Object
targets : list<Object>
这些属性确定受此操作影响的项目及其属性。
2、exclude : list<Object>
此属性包含不应受此操作影响的对象。
3、value : any
此属性保存要在属性上设置的值。
如果 PropertyAction 是在 Transition 或 Behavior 中定义的,则此值默认为在 Transition 的结束状态中定义的值,或触发 Behavior 的属性更改的值。