ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

QML —— 顺序动画,足球落地示例(附完整源码)

2026/8/16 3:10:04 拓冰建站 浏览量
QML —— 顺序动画,足球落地示例(附完整源码)

效果

源码
import QtQuick 2.12
import QtQuick.Window 2.12Window
{visible: truewidth: 640height: 480title: qsTr("Hello World")MouseArea{anchors.fill: parentonClicked:{setSequentialAnimationState(true)}}Component.onCompleted:{setSequentialAnimationState(false)}Component.onDestruction:{setSequentialAnimationState(false)}function setSequentialAnimationState(b){if(b){if(!sequentialAnimation.running){sequentialAnimation.start()}}else{if(sequentialAnimation.running){sequentialAnimation.stop()}}}Image{id: ballImgsource: "ball.jpeg"scale: 0.3y: -heightanchors.horizontalCenter: parent.horizontalCenterSequentialAnimation on y{id: sequentialAnimationloops: Animation.InfiniteNumberAnimation{id: fallNumberAnimationto: ballImg.parent.height - ballImg.heighteasing.type: Easing.OutBounceduration: 2000}PauseAnimation {duration: 1000}NumberAnimation{to: -ballImg.heighteasing.type: Easing.OutQuadduration: 500}}}
}

关注

笔者 - jxd