QML利用粒子效果DIY进度条 QtQuick.particles

先放实现的简单效果吧
在这里插入图片描述

最简单的一类QML粒子特效,只是发射ImageParticle即可
通过ParticleSystem建立一个粒子系统,ImageParticle可以将图片加载为需要发射的粒子素材
最后通过Emitter发射,调整位置,发射速率,存活时长,色彩变化,加速度等属性从而获得理想的效果

import QtQuick 2.12
import QtQuick.Controls 2.5
//import QtGraphicalEffects 1.12
import QtQuick.Particles 2.12

Rectangle {
    id: proBar;
    width: 256;
    height: 30;
    color: ui.colorClouds;
    radius: 5;
    property var value: 0;
    property var maxValue: 0;
    
    onValueChanged: {
        if(value === maxValue){
            partEmt.enabled = false;
        }
        else{
            partEmt.enabled = true;
        }
    }
    
    onMaxValueChanged: {
        if(value !== maxValue){
            partEmt.enabled = true;
        }
    }

    Rectangle{
        id: bar;
        color: Qt.rgba(Math.random()*2, Math.random()*2, Math.random()*2, 0.8);
        height: parent.height /// 2;Qt.rgba(Math.random(), Math.random(), Math.random(), 1);
        anchors.left: parent.left;
        width: 0;
        radius: 4;
        /*Timer{
            interval: 3000;
            running: true;
            repeat: true;
            onTriggered: ColorAnimation{
                id: colorDur;
                target: bar;
                duration: 600;
                easing.type: Easing.InQuart;
                to: Qt.rgba(Math.random()*0.8, Math.random()*0.8, Math.random()*0.8, 1);
            }
        }*///原本想实现定时变色功能
    }
    Rectangle{
        color: parent.color;
        height: parent.height /// 2;
        anchors.right: parent.right;
        width: parent.width - partEff.width - bar.width;
        radius: 4;
    }
    
    ParticleSystem {
        id: partEff;
        clip: false;
        height: parent.height;
        anchors.left: bar.right;
        anchors.leftMargin: -3;
        width: 60;
        ImageParticle {
            id: imgPart;
            alpha: 0.95;
            groups: ["S"];
            anchors.fill: parent;
            source: "qrc:/Components/Resource/Image/atom.png";
            color: bar.color;
            //greenVariation: 0.8
            //color: Qt.rgba(Math.random()*0.8, Math.random()*0.8, Math.random()*0.8, 1);
            colorVariation: 0.7;
        }
        Emitter {
            id: partEmt;
            anchors.verticalCenter: parent.verticalCenter;
            group: "S";
            emitRate: 100;
            lifeSpan: 600;
            size: 6;
            sizeVariation: -5;
            velocity: PointDirection{ x: 100; xVariation: 60; yVariation: 40}
            width: 5;
            height: bar.height * 0.98;
        }
    }
    
    PropertyAnimation{
        target: bar;
        property: "width";
        to: proBar.value / maxValue * (parent.width - partEff.width);
        duration: 500;
        easing.type: Easing.InQuart;
        onToChanged: start();
    }
}
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值