新建基于Widget的应用程序,在ui的窗口中添加QLabel,对象名label,调整整个窗口大小。
准备loading.gif图片
Widget.cpp
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#include "widget.h"
#include "ui_widget.h" #include <QMovie> #include <QDesktopWidget> Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); setWindowFlags(Qt::FramelessWindowHint); //无边框 setAttribute(Qt::WA_TranslucentBackground); //背景透明 //屏幕居中显示 int frmX = width(); int frmY = height(); QDesktopWidget w; int deskWidth = w.width(); int deskHeight = w.height(); QPoint movePoint(deskWidth / 2 - frmX / 2, deskHeight / 2 - frmY / 2); move(movePoint); //加载gif图片 QMovie *movie = new QMovie(":/img/loading.gif"); ui->label->setMovie(movie); movie->start(); } Widget::~Widget() { delete ui; } |