import QtQuick 2.12
import QtQuick.Window 2.12
Window {
id: root
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Rectangle {
id: rect
width: parent.width / 4
height: parent.height / 4
color: 'red'
// 这个是便捷方式等效于下面的
// NumberAnimation on width {
// id: rectAnimation
// to: root.width / 2
// duration: 1000
// running: false
// }
NumberAnimation {
id: rectAnimation
target: rect
properties: 'width'
to: root.width / 2 // 动画目标的宽度
duration: 1000 // 持续时间
running: false // 先不运行
}
MouseArea {
anchors.fill: parent
property bool flag: false
onClicked: {
console.log(rect.width)
if (!flag)
rectAnimation.to = root.width / 2
else
rectAnimation.to = root.width / 4
rectAnimation.running = true
flag = !flag
}
}
}
}
Qml NumberAnimation动画简单示例
最新推荐文章于 2023-12-05 23:55:24 发布