当前位置: 首页 > news >正文

QML 实现一个动态的启动界面

QML 实现一个动态的启动界面

  • 一、效果查看
  • 二、源码分享
  • 三、所用到的资源下载

一、效果查看

在这里插入图片描述

二、源码分享

工程结构
在这里插入图片描述

main.qml

import QtQuick
import QtQuick.Controls
import QtQuick.Dialogs
import Qt.labs.platform

Window {
    id:window
    width: 640
    height: 400
    visible: true
    title: qsTr("Hello World")

    property int imageCnt: 1

    Rectangle{
        anchors.fill: parent
        gradient: Gradient{
            orientation: Gradient.Vertical
            GradientStop { position: 0.0; color: "#4bb6ac" }
            GradientStop { position: 0.5; color: "#3edabd" }
            GradientStop { position: 1.0; color: "#24efc0" }
        }
    }

     Timer{
         interval: 2000
         repeat: true
         running:true
         onTriggered: {
             var w = Qt.createComponent("DynamicImage.qml")
             if (w.status === Component.Ready) {
                var image = "qrc:/image/image"+imageCnt+".svg";
                imageCnt += 1
                if(imageCnt > 10)
                    imageCnt = 1

                var endX = Math.floor(Math.random()*window.width);
                console.log(image,endX)
                var item = w.createObject(window,{x:window.width/2-50,y:window.height,
                                                       width:100,height:100,source:image,
                                                       stopX:endX,stopY:-150,originX:0,originy:50,
                                                       moveDuration:15000,rotationDuration: 5000,
                                                       running: true});
                console.log("create:"+item)
                item.moveFinished.connect(()=>{
                                           item.destroy()
                                            console.log("destroyed:"+item)
                                       })
            }
            else console.error("create component falied!");


         }
     }

    Text{
        id:btn
        width: 200
        height: 100
        z:1
        anchors.centerIn: parent
        text: "正在启动中...请稍后!"
        color:"white"
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        font.pixelSize: 30
        font.bold: true
        font.italic: true
    }

}

DynamicImage.qml

//DynamicImage.qml
import QtQuick
import QtQuick.Controls

Image{
    id:root
    property int stopX: 0
    property int stopY: 0
    property alias originX: rotation.origin.x
    property alias originy: rotation.origin.y
    property int moveDuration: 5000
    property int rotationDuration: 5000
    property bool running: false

    signal moveFinished()

    transform: Rotation{
        id:rotation

        axis.x: 0
        axis.y: 0
        axis.z: 1
    }
    RotationAnimation{
        running: root.running
        target: root
        from:0
        to:360
        loops:Animation.Infinite
        duration: rotationDuration
    }
    ParallelAnimation{
        id:anim
        running:root.running
        NumberAnimation{
            target: root
            properties: "x"
            from:root.x
            to:stopX
            duration: moveDuration
        }
        NumberAnimation{
            target: root
            properties: "y"
            from:root.y
            to:stopY
            duration: moveDuration
        }
        onFinished: {
            moveFinished()
            console.log("onFinished")
        }
    }
    Component.onDestruction: {
        //console.log("onDestroyed")
    }
}



三、所用到的资源下载

本博文最前面下载。

相关文章:

  • Apipost和Apifox如何选型(1):WebSocket调试
  • 【Elasticsearch】多索引(数据流)搜索
  • conda 配置源
  • CSDN违禁词与规避(CSDN社区专属)
  • 零基础学QT、C++(四)QT程序打包
  • 利用Linux技能处理访问升级
  • UE_C++ —— Container TSet
  • AIGC视频扩散模型新星:SVD——稳定扩散的Video模型
  • 服务保护和分布式事务
  • buu-get_started_3dsctf_2016-好久不见39
  • WordPress自定义排序插件:Simple Custom Post Order完全指南(SEO优化版)
  • 探讨一下游戏的重要性
  • netcore libreoffice
  • Windows - 通过ssh打开带有图形界面的程序 - 一种通过计划任务的曲折实现方式
  • 2024年数字政府服务能力优秀创新案例汇编(附下载)
  • 【QT中的一些高级数据结构,持续更新中...】
  • 高精度算法解析与实现(c++)
  • QT实战-基于QWidget实现的异形tip窗口
  • Python爬虫实战:获取12306特定日期、城市车票信息,并做数据分析以供出行参考
  • AcWing走迷宫-最短路问题-BFS求解
  • 网站怎么做边框/最近七天的新闻重点
  • 昆明网页制作开发/哈尔滨seo优化
  • wordpress手机注册验证/网站seo站群软件
  • 凉州区新农村建设网站/seo的概念是什么
  • 苏州正规做网站公司/武汉网站建设
  • 餐饮网站网页设计代码/西安网络优化大的公司