QT 加载GIF动图的方法(记录一下)

.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include 
#include 

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QMovie *ptr_movie = new QMovie(":/abcd.gif");
    ui->label->setMovie(ptr_movie);
    ptr_movie->start();

    QObject::connect(ptr_movie,&QMovie::frameChanged,[=](int frameNumber)
    {
        if (frameNumber == ptr_movie->frameCount()-1)
        {
            ptr_movie->stop();
        }
    });

}

MainWindow::~MainWindow()
{
    delete ui;
}

你可能感兴趣的:(qt,ui,开发语言)