QML工作笔记-NumberAnimation、RotationAnimation、Timer综合使用
发布日期:2021-06-30 11:01:22 浏览次数:2 分类:技术文章

本文共 2061 字,大约阅读时间需要 6 分钟。

目录

 


 

例子及演示

运行截图如下:

git图如下:

程序结构如下:

源码如下:

main.cpp

#include 
#include
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.9import QtQuick.Window 2.2Window {    visible: true    width: 800    height: 600    title: qsTr("CSDN IT1995")    id: windows    //背景    Image{        source: "qrc:/img/back.jpg"        MouseArea{            onClicked: {                numberAnimation1.stop();                console.debug("Hello");            }        }    }    Image {        id: img1;        x: 50        y: windows.height / 2 - 50        source: "qrc:/img/img.png"        NumberAnimation on x{            id : numberAnimation1            to : windows.width / 2 - 170            duration: 400            loops: Animation.Infinite        }    }    Image {        id: img2;        x: windows.width - 200        y: windows.height / 2 - 80        source: "qrc:/img/img2.png"        NumberAnimation on x{            id : numberAnimation2            to : windows.width / 2            duration: 400            loops: Animation.Infinite        }        RotationAnimation on rotation {            to : 360            from: 0            duration: 400            loops: 100        }    }    MouseArea{        anchors.fill: parent        onClicked: {            numberAnimation1.start();            numberAnimation2.start();            timer.start();        }    }    Timer{        id: timer        interval: 20        running: false        repeat: true        onTriggered: {            if(img1.x + 171 > img2.x){                console.debug("爆炸了");                timer.stop()                img1.visible = false;                img2.visible = false;            }        }    }    Component.onCompleted: {        numberAnimation1.stop();        numberAnimation2.stop();    }}

 

打包下载

地址:

转载地址:https://it1995.blog.csdn.net/article/details/90171943 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Qt工作笔记-qmake和uic(对Qt底层的进一步认识)
下一篇:Arduino笔记-温度传感器的使用

发表评论

最新留言

感谢大佬
[***.8.128.20]2024年04月21日 13时14分01秒