Qt 简约又简单的加载动画 第七季 音量柱风格
今天和大家分享两个音量柱风格的加载动画,这次的加载动画的最大特点就是简单,只有几行代码. 效果如下:

一共三个文件,可以直接编译运行
//main.cpp
#include "LoadingAnimWidget.h"
#include <QApplication>
#include <QGridLayout>
int main(int argc, char *argv[])
{QApplication a(argc, argv);QWidget w;w.setWindowTitle("加载动画 第7季");QGridLayout * mainLayout = new QGridLayout;auto* anim1= new MagnitudeMeter;mainLayout->addWidget(anim1,0,0);auto* anim2 = new MagnitudeMeter;mainLayout->addWidget(anim2,0,1);anim2->setColor("lightblue");auto* anim3 = new MagnitudeMeter;mainLayout->addWidget(anim3,0,2);anim3->setColor("slateblue");auto* anim4 = new ThreeColumn;mainLayout->addWidget(anim4,1,0);auto* anim5 = new ThreeColumn;mainLayout->addWidget(anim5,1,1);anim5->setColor("lightblue");auto* anim6 = new ThreeColumn;mainLayout->addWidget(anim6,1,2);anim6->setColor("slateblue");w.setLayout(mainLayout);w.show();anim1->start();anim2->start();anim3->start();anim4->start();anim5->start();anim6->start();return a.exec();
}
//LoadingAnimWidget.h
#ifndef LOADINGANIMWIDGET_H
#define LOADINGANIMWIDGET_H
#include <QPropertyAnimation>
#include <QWidget>
class LoadingAnimBase:public QWidget
{Q_OBJECTQ_PROPERTY(qreal angle READ angle WRITE setAngle)
public:LoadingAnimBase(QWidget* parent=nullptr);virtual ~LoadingAnimBase();qreal angle()const;void setAngle(qreal an);
public slots:virtual void exec();virtual void start();virtual void stop();
protected:QPropertyAnimation mAnim;qreal mAngle;
};class MagnitudeMeter:public LoadingAnimBase{//一个类似音量检测器的动画,有一排小柱子,它们的高度随时变化
public:MagnitudeMeter(QWidget* parent = nullptr);void setColor(const QColor& color);
protected:void paintEvent(QPaintEvent*);
private:QColor mColor;
};
class ThreeColumn:public LoadingAnimBase{//上一个的简化版,三个循环变化高度的小柱子
public:ThreeColumn(QWidget* parent = nullptr);void setColor(const QColor& color);
protected:void paintEvent(QPaintEvent*);
private:QColor mColor;
};
#endif
//LoadingAnimWidget.cpp
#include "LoadingAnimWidget.h"
#include <QDebug>
#include <QPaintEvent>
#include <QPainter>
#include <QtMath>
#include <QRandomGenerator>
LoadingAnimBase::LoadingAnimBase(QWidget* parent):QWidget(parent){mAnim.setPropertyName("angle");mAnim.setTargetObject(this);mAnim.setDuration(2000);mAnim.setLoopCount(-1);//run forevermAnim.setEasingCurve(QEasingCurve::Linear);setFixedSize(200,200);mAngle = 0;
}
LoadingAnimBase::~LoadingAnimBase(){}
void LoadingAnimBase::exec(){if(mAnim.state() == QAbstractAnimation::Stopped){start();}else{stop();}
}
void LoadingAnimBase::start(){mAnim.setStartValue(0);mAnim.setEndValue(360);mAnim.start();
}
void LoadingAnimBase::stop(){mAnim.stop();
}
qreal LoadingAnimBase::angle()const{ return mAngle;}
void LoadingAnimBase::setAngle(qreal an){mAngle = an;update();
}MagnitudeMeter::MagnitudeMeter(QWidget* parent):LoadingAnimBase(parent),mColor("cadetblue"){mAnim.setDuration(8000);
}
void MagnitudeMeter::setColor(const QColor& color){if(mColor != color){mColor = color;update();}
}void MagnitudeMeter::paintEvent(QPaintEvent*){QPainter painter(this);painter.setRenderHint(QPainter::Antialiasing);painter.setPen(Qt::NoPen);painter.setBrush(QBrush(mColor));const qreal x = width();const qreal y = height();static const int amount = 8;//8个小柱子static const int gap = 2;//小柱子之间的间距const qreal w = (0.667*x - (amount-1)*gap) / amount;painter.translate(x/6,0.667*y);static QList<qreal> offsetList;static QList<qreal> factorList;if(offsetList.size() <= 0){QRandomGenerator g;for(int i = 0;i < amount;++i) offsetList.push_back(g.bounded(1.0) * 2*M_PI);for(int i = 0;i < amount;++i) factorList.push_back(g.bounded(4) + 1);//周期不一样}for(int i = 0;i < amount;++i){const int maxh = y/3;const int h = (1+qSin((2*M_PI/360 * mAngle * factorList[i]) + offsetList[i]))/2 * 0.8*maxh+0.2*maxh;painter.drawRect(i*(gap + w),-h,w,h);}
}
ThreeColumn::ThreeColumn(QWidget* parent):LoadingAnimBase (parent),mColor("cadetblue"){}
void ThreeColumn::setColor(const QColor& color){if(mColor != color){mColor = color;update();}
}
void ThreeColumn::paintEvent(QPaintEvent*){QPainter painter(this);painter.setRenderHint(QPainter::Antialiasing);painter.setPen(Qt::NoPen);painter.setBrush(QBrush(mColor));const qreal x = width();const qreal y = height();painter.translate(x/2,y/2);static const int w = 8;static const int h = 16;static const int gap = 4;qreal h1 = h/2+h/2*qSin(-2*M_PI/360*mAngle);qreal h2 = h/2+h/2*qSin(-2*M_PI/360*mAngle + M_PI*2/3);qreal h3 = h/2+h/2*qSin(-2*M_PI/360*mAngle + M_PI*4/3);qreal yList[3] = {-h1,-h2,-h3};qreal xList[3] = {-1.5*w-gap,-0.5*w,0.5*w+gap};for(int i = 0;i < 3;++i){painter.drawRect(QRectF(xList[i],yList[i],w,-2*yList[i]));}
}
相关文章:
Qt 简约又简单的加载动画 第七季 音量柱风格
今天和大家分享两个音量柱风格的加载动画,这次的加载动画的最大特点就是简单,只有几行代码. 效果如下: 一共三个文件,可以直接编译运行 //main.cpp #include "LoadingAnimWidget.h" #include <QApplication> #include <QGridLayout> int main(int argc…...
【JS】数值精度缺失问题解决方案
方法一: 保留字符串类型,传给后端 方法二: 如果涉及到计算,用以下方法 // 核心思想 在计算前,将数字乘以相同倍数,让他没有小数位,然后再进行计算,然后再除以相同的倍数࿰…...
c++基础知识补充4
单独使用词汇 using std::cout; 隐式类型转换型初始化:如A a1,,此时可以形象地理解为int i1;double ji;,此时1可以认为创建了一个值为1的临时对象,然后对目标对象进行赋值,当对象为多参数时,使用(1…...
leetcode230. 二叉搜索树中第K小的元素
lletcode 230. 二叉搜索树中第K小的元素,链接:https://leetcode.cn/problems/kth-smallest-element-in-a-bst 题目描述 给定一个二叉搜索树的根节点 root ,和一个整数 k ,请你设计一个算法查找其中第 k 个最小元素(从 …...
医学大数据|文献阅读|有关“肠癌+机器学习”的研究记录
目录 1.机器学习算法识别结直肠癌中的免疫相关lncRNA signature 2.基于机器学习的糖酵解相关分子分类揭示了结直肠癌癌症患者预后、TME和免疫疗法的差异,2区7 3.整合深度学习-病理组学、放射组学和免疫评分预测结直肠癌肺转移患者术后结局 4.最新7.4分纯生信&am…...
Linux信号【systemV】
目录 前言 正文: 1消息队列 1.1什么是消息队列? 1.2消息队列的数据结构 1.3消息队列的相关接口 1.3.1创建 1.3.2释放 1.3.3发送 1.3.4接收 1.4消息队列补充 2.信号量 2.1什么是信号量 2.2互斥相关概念 2.3信号量的数据结构 2.4…...
node.js最准确历史版本下载
先进入官网:Node.js https://nodejs.org/en 嫌其他博客多可以到/release下载:Node.js,在blog后面加/release https://nodejs.org/en/blog/release/ 点击next翻页,同样的道理...
UE5 C++ 单播 多播代理 动态多播代理
一. 代理机制,代理也叫做委托,其作用就是提供一种消息机制。 发送方 ,接收方 分别叫做 触发点和执行点。就是软件中的观察者模式的原理。 创建一个C Actor作为练习 二.单播代理 创建一个C Actor MyDeligateActor作为练习 在MyDeligateAc…...
前端学习、CSS
CSS可以嵌入到HTML中使用。 每个CSS语法包含两部分,选择器和应用的属性。 div用来声明针对页面上的哪些元素生效。 具体设置的属性以键值对形式表示,属性都在{}里,属性之间用;分割,键和值之间用:分割。 因为CSS的特殊命名风格…...
Flink基本原理 + WebUI说明 + 常见问题分析
Flink 概述 Flink 是一个用于进行大规模数据处理的开源框架,它提供了一个流式的数据处理 API,支持多种编程语言和运行时环境。Flink 的核心优点包括: 低延迟:Flink 可以在毫秒级的时间内处理数据,提供了低延迟的数据…...
3. 文档概述(Documentation Overview)
3. 文档概述(Documentation Overview) 本章节简要介绍一下Spring Boot参考文档。它包含本文档其它部分的链接。 本文档的最新版本可在 docs.spring.io/spring-boot/docs/current/reference/ 上获取。 3.1 第一步(First Steps) …...
【vue3 路由使用与讲解】vue-router : 简洁直观的全面介绍
# 核心内容介绍 路由跳转有两种方式: 声明式导航:<router-link :to"...">编程式导航:router.push(...) 或 router.replace(...) ;两者的规则完全一致。 push(to: RouteLocationRaw): Promise<NavigationFailur…...
ubuntu创建账号和samba共享目录
新建用于登录Ubuntu图形界面的用户 sudo su #切换为root用户获取管理员权限用于新建用户 adduser username #新建用户(例如用户名为username) adduser username sudo #将用户添加到 sudo 组 新建只能用于命令行下登录的用户 sudo su #切换为root用户…...
李沐动手学习深度学习——3.6练习
本节直接实现了基于数学定义softmax运算的softmax函数。这可能会导致什么问题?提示:尝试计算exp(50)的大小。 可能存在超过计算机最大64位的存储,导致精度溢出,影响最终计算结果。 本节中的函数cross_entropy是根据交叉熵损失函数…...
机器学习_10、集成学习-Bagging(自举汇聚法)
Bagging(自举汇聚法) Bagging(Bootstrap Aggregating,自举汇聚法)是一种集成学习方法,由Leo Breiman于1996年提出。它旨在通过结合多个模型来提高单个预测模型的稳定性和准确性。Bagging方法特别适用于减少…...
【力扣hot100】刷题笔记Day20
前言 今天学习了一句话“自己如果不努力,屎都吃不上热乎的”,话糙理不糙,与君共勉 35. 搜索插入位置 - 力扣(LeetCode) 二分查找 class Solution:def searchInsert(self, nums: List[int], target: int) -> int:n…...
Redis 之八:Jdeis API 的使用(Java 操作 Redis)
Jedis API 使用 Jedis 是 Redis 官方推荐的 Java 客户端,它提供了一套丰富的 API 来操作 Redis 服务器。通过 Jedis API,开发者可以方便地在 Java 应用程序中执行 Redis 的命令来实现数据的增删查改以及各种复杂的数据结构操作。 以下是一些基本的 Jedis…...
Docker 应用入门
一、Docker产生的意义 1‘解决环境配置难题:在软件开发中最大的麻烦事之一,就是环境配置。为了跑我们的程序需要装各种插件,操作系统差异、不同的版本插件都可能对程序产生影响。于是只能说:程序在我电脑上跑是正常的。 2’解决资…...
朱维群将出席用碳不排碳碳中和顶层科技路线设计开发
演讲嘉宾:朱维群 演讲题目:“用碳不排碳”碳中和顶层科技路线设计开发 简介 姓名:朱维群 性别:男 出生日期:1961-09-09 职称:教授 1998年毕业于大连理工大学精细化工国家重点实验室精细化工专业&#x…...
linux如何查看磁盘占用情况
要查看Linux系统中磁盘的占用情况,可以使用一些命令来获取相关信息。以下是一些常用的命令: df命令: df命令用于显示文件系统的磁盘空间使用情况,包括磁盘分区的总空间、已用空间、可用空间等信息。 df -h使用 -h 参数可以以人类可…...
Vim 调用外部命令学习笔记
Vim 外部命令集成完全指南 文章目录 Vim 外部命令集成完全指南核心概念理解命令语法解析语法对比 常用外部命令详解文本排序与去重文本筛选与搜索高级 grep 搜索技巧文本替换与编辑字符处理高级文本处理编程语言处理其他实用命令 范围操作示例指定行范围处理复合命令示例 实用技…...
Python|GIF 解析与构建(5):手搓截屏和帧率控制
目录 Python|GIF 解析与构建(5):手搓截屏和帧率控制 一、引言 二、技术实现:手搓截屏模块 2.1 核心原理 2.2 代码解析:ScreenshotData类 2.2.1 截图函数:capture_screen 三、技术实现&…...
Linux应用开发之网络套接字编程(实例篇)
服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …...
树莓派超全系列教程文档--(61)树莓派摄像头高级使用方法
树莓派摄像头高级使用方法 配置通过调谐文件来调整相机行为 使用多个摄像头安装 libcam 和 rpicam-apps依赖关系开发包 文章来源: http://raspberry.dns8844.cn/documentation 原文网址 配置 大多数用例自动工作,无需更改相机配置。但是,一…...
黑马Mybatis
Mybatis 表现层:页面展示 业务层:逻辑处理 持久层:持久数据化保存 在这里插入图片描述 Mybatis快速入门  本地文件记录:保存已…...
spring:实例工厂方法获取bean
spring处理使用静态工厂方法获取bean实例,也可以通过实例工厂方法获取bean实例。 实例工厂方法步骤如下: 定义实例工厂类(Java代码),定义实例工厂(xml),定义调用实例工厂ÿ…...
大学生职业发展与就业创业指导教学评价
这里是引用 作为软工2203/2204班的学生,我们非常感谢您在《大学生职业发展与就业创业指导》课程中的悉心教导。这门课程对我们即将面临实习和就业的工科学生来说至关重要,而您认真负责的教学态度,让课程的每一部分都充满了实用价值。 尤其让我…...
HashMap中的put方法执行流程(流程图)
1 put操作整体流程 HashMap 的 put 操作是其最核心的功能之一。在 JDK 1.8 及以后版本中,其主要逻辑封装在 putVal 这个内部方法中。整个过程大致如下: 初始判断与哈希计算: 首先,putVal 方法会检查当前的 table(也就…...
Xen Server服务器释放磁盘空间
disk.sh #!/bin/bashcd /run/sr-mount/e54f0646-ae11-0457-b64f-eba4673b824c # 全部虚拟机物理磁盘文件存储 a$(ls -l | awk {print $NF} | cut -d. -f1) # 使用中的虚拟机物理磁盘文件 b$(xe vm-disk-list --multiple | grep uuid | awk {print $NF})printf "%s\n"…...
