平滑动画是numberAnimation的子类,只是默认的easing.type被做了改动而已。
现在要做的是单击鼠标以后,一个红色的矩形框可以一直跟随鼠标。
代码来自Qt Quick核心编程这本书 作者安晓辉
代码如下:
import QtQuick 2.3
import QtQuick.Window 2.2
Window {
visible: true
width: 300
height: 300
MouseArea {
anchors.fill: parent
onClicked: {
followAnimationy.from=follow.y
followAnimationy.to=mouseY+4
followAnimationy.start()
followAnimationx.from=follow.x
followAnimationx.to=mouseX+4
followAnimationx.start()
}
}
Rectangle{
id:follow
x:0
y:0
width: 100
height: 100
color: "red"
}
SmoothedAnimation{
id:followAnimationy
target: follow
property: "y"
duration: 3000
}
SmoothedAnimation{
id:followAnimationx
targe