Qt 简约美观的动画 摆钟风格 第十季

😊 今天给大家分享一个摆钟风格的加载动画 😊
效果如下:
在这里插入图片描述
最近工作忙起来了 , 后续再分享其他有趣的加载动画吧.
一共三个文件 , 可以直接编译运行

//main.cpp
#include "LoadingAnimWidget.h"
#include <QApplication>
#include <QGridLayout>
int main(int argc, char *argv[])
{
   
   
    QApplication a(argc, argv);
    QWidget w;
    w.setWindowTitle("加载动画 第10季");
    QGridLayout * mainLayout = new QGridLayout;

    auto* anim1 = new ThreeMovingZoomingBalls;
    mainLayout->addWidget(anim1,0,0);

    auto* anim2 = new FourRotatingFireBall;
    mainLayout->addWidget(anim2,0,1);

    auto* anim3 = new CookieMonster;
    mainLayout->addWidget(anim3,0,2);

    auto* anim4 = new StickCircle;
    anim4->setStickColor("lime");
    anim4->setStickWidth(16);
    anim4->setStickLength(32);
    mainLayout->addWidget(anim4,1,0);

    auto* anim5 = new PendulumClock;
    mainLayout->addWidget(anim5,1,1);

    auto* anim6 = new AmpereMeter;
    mainLayout->addWidget(anim6,1,2);

    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_OBJECT
    Q_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 StickCircle:public LoadingAnimBase
{
   
   
    Q_OBJECT
public:
    explicit StickCircle(QWidget* parent = nullptr);
    void setStickLength(qreal len);
    void setStickWidth(qreal len);
    void setStickColor(const QColor& color);
protected:
    void paintEvent(QPaintEvent *event);
private:
    qreal mStickLen;
    qreal mStickWidth;
    QColor mStickColor;
};
class ThreeMovingZoomingBalls:public LoadingAnimBase{
   
   //三个一边移动一边缩放的小球
public:
    ThreeMovingZoomingBalls(QWidget* parent = nullptr);
protected:
    void paintEvent(QPaintEvent*);
};
class FourRotatingFireBall:public LoadingAnimBase{
   
   //四个旋转的火球,说他是火球是因为快速转动的时候它有残影,看上去像弧线
public:
    FourRotatingFireBall(QWidget* parent = nullptr);
protected:
    void paintEvent(QPaintEvent*);
};
class CookieMonster
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值