C
Qt Quick Ultralite 时间轴示例
演示如何在Qt Quick Ultralite中使用时间轴。
概述
该timeline 示例演示了如何使用“时间轴”类型。它展示了一个循环动画:两个矩形在从左向右移动的同时,颜色从红色变为绿色。随后,颜色动画停止,矩形向垂直中心移动。过了一会儿,动画将以相反方向播放,并在动画结束时重新开始循环。


目标平台
项目结构
CMake 项目文件
CMakeLists.txt 文件包含该示例的构建脚本。
QmlProject 文件
要使用Timeline 模块,必须将其导入到Timeline 的模块中:
...
ModuleFiles {
MCU.qulModules: ["Timeline"]
}
...应用程序的用户界面
timeline.qml 定义了显示在屏幕上的应用程序用户界面。
import QtQuick 2.15 import QtQuick.Timeline 1.0 Rectangle { id: root readonly property int rectSize: root.height / 5 color: "#c2c2c2" Timeline { id: timeline1 animations: [ TimelineAnimation { id: timelineAnimation pingPong: true running: true from: 0 duration: 5000 loops: Animation.Infinite to: 800 } ] startFrame: 0 enabled: true endFrame: 10000 KeyframeGroup { target: rectangle property: "x" Keyframe { id: d value: root.width - rectangle.width frame: 300 } Keyframe { value: root.width - rectangle.width frame: 548 } } KeyframeGroup { target: rectangle property: "y" Keyframe { value: 0 frame: 300 } Keyframe { value: root.height * 0.5 - rectangle.height frame: 552 } } KeyframeGroup { target: rectangle property: "color" Keyframe { value: "red" frame: 0 easing.type: Easing.InCubic } Keyframe { value: "green" frame: 552 easing.type: Easing.OutCubic } } KeyframeGroup { target: rectangle1 property: "x" Keyframe { value: root.width - rectangle1.width frame: 300 } Keyframe { value: root.width - rectangle1.width frame: 548 } } KeyframeGroup { target: rectangle1 property: "y" Keyframe { value: root.height - rectangle1.height frame: 0 } Keyframe { value: root.height - rectangle1.height frame: 300 } Keyframe { value: root.height * 0.5 frame: 548 } } KeyframeGroup { target: rectangle1 property: "color" Keyframe { value: "red" frame: 0 easing.type: Easing.OutCubic } Keyframe { value: "green" frame: 552 easing.type: Easing.OutCubic } } KeyframeGroup { target: text property: "text" Keyframe { value: "2" frame: 300 } Keyframe { value: "3" frame: 548 } } } Rectangle { id: rectangle x: 0 y: 0 width: rectSize height: rectSize color: "#ffffff" } Rectangle { id: rectangle1 x: 0 y: root.height - height width: rectSize height: rectSize color: "#ffffff" Text { id: text anchors.centerIn: parent text: "1" } } }
文件:
另请参阅 Timeline 。
在某些 Qt 许可下可用。
了解更多信息。