Qt 使用QLabel、QMovie加載gif圖片實現動態等待窗口


新建基於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;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM