waitfortheloading.h
#ifndef WAITFORTHELOADING_H
#define WAITFORTHELOADING_H
#include <QWidget>
namespace Ui {
class WaitForTheLoading;
}
class QMovie;
class WaitForTheLoading : public QWidget
{
Q_OBJECT
public:
explicit WaitForTheLoading(QWidget *parent = nullptr);
~WaitForTheLoading();
private:
Ui::WaitForTheLoading *ui;
QMovie *m_pGifMovie = nullptr;
};
#endif // WAITFORTHELOADING_H
waitfortheloading.cpp
#include <QMovie>
#include "waitfortheloading.h"
#include "ui_waitfortheloading.h"
WaitForTheLoading::WaitForTheLoading(QWidget *parent) :
QWidget(parent),
ui(new Ui::WaitForTheLoading)
{
ui->setupUi(this);
//设置窗口为模态但是不阻塞主界面
setWindowModality(Qt::ApplicationModal);
//设置窗口无边框与不显示任务栏图标
setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::SubWindow);
//设置窗口背景透明
setAttribute(Qt::WA_TranslucentBackground);
//设置窗口关闭时自动释放
setAttribute(Qt::WA_DeleteOnClose);
//设置GIF动画
m_pGifMovie = new QMovie(":/res/image/loading.gif", QByteArray(), this);
ui->label->setMovie(m_pGifMovie);
m_pGifMovie->start();
}
WaitForTheLoading::~WaitForTheLoading()
{
delete ui;
}