QML工作笔记-NumberAnimation、RotationAnimation、Timer综合使用
生活随笔
收集整理的這篇文章主要介紹了
QML工作笔记-NumberAnimation、RotationAnimation、Timer综合使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
?
例子及演示
打包下載
?
例子及演示
運行截圖如下:
git圖如下:
程序結構如下:
源碼如下:
main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine>int main(int argc, char *argv[]) {QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);QGuiApplication app(argc, argv);QQmlApplicationEngine engine;engine.load(QUrl(QStringLiteral("qrc:/main.qml")));if (engine.rootObjects().isEmpty())return -1;return app.exec(); }main.qml
import QtQuick 2.9 import QtQuick.Window 2.2Window {visible: truewidth: 800height: 600title: qsTr("CSDN IT1995")id: windows//背景Image{source: "qrc:/img/back.jpg"MouseArea{onClicked: {numberAnimation1.stop();console.debug("Hello");}}}Image {id: img1;x: 50y: windows.height / 2 - 50source: "qrc:/img/img.png"NumberAnimation on x{id : numberAnimation1to : windows.width / 2 - 170duration: 400loops: Animation.Infinite}}Image {id: img2;x: windows.width - 200y: windows.height / 2 - 80source: "qrc:/img/img2.png"NumberAnimation on x{id : numberAnimation2to : windows.width / 2duration: 400loops: Animation.Infinite}RotationAnimation on rotation {to : 360from: 0duration: 400loops: 100}}MouseArea{anchors.fill: parentonClicked: {numberAnimation1.start();numberAnimation2.start();timer.start();}}Timer{id: timerinterval: 20running: falserepeat: trueonTriggered: {if(img1.x + 171 > img2.x){console.debug("爆炸了");timer.stop()img1.visible = false;img2.visible = false;}}}Component.onCompleted: {numberAnimation1.stop();numberAnimation2.stop();}}?
打包下載
地址:https://github.com/fengfanchen/Qt/tree/master/AnimationTest1QML
總結
以上是生活随笔為你收集整理的QML工作笔记-NumberAnimation、RotationAnimation、Timer综合使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: QML笔记-在背景图中添加NumberA
- 下一篇: Flask笔记-session安全问题(