用QT的,加載的一張gif圖片。記錄下來以後免得忘記。 [cpp] #ifndef DIALOG_H #define DIALOG_H #include <QDialog> #include <QLabel> #include<QPainter> #include<QMovie> class Dialog : public QDialog { Q_OBJECT public: explicit Dialog(QWidget *parent = 0); ~Dialog(); private: QMovie *movie; QLabel *label; }; #endif // DIALOG_H [cpp] #include"dialog.h" Dialog::Dialog(QWidget*parent): QDialog(parent) { www.2cto.com label = new QLabel(this); this->setFixedSize(200,200); setWindowOpacity(0.5); //設置透明用; this->setWindowFlags(Qt::Dialog|Qt::CustomizeWindowHint); //取消對話框標題 //this->setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint); //取消對話框標題和邊框 //this->setAutoFillBackground(true); this->setContentsMargins(0,0,0,0); label->setContentsMargins(0,0,0,0); /*QPalettepalette;palette.setBrush(QPalette::Background,QBrush(QPixmap("E:/qml/imgdialog/loading.gif"))); this->setPalette(palette)*/; movie = new QMovie("loading.gif"); label->setMovie(movie); movie->start(); } Dialog::~Dialog() { delete label; delete movie; } 效果: