GIF animation in Qt

后端 未结 4 1377
慢半拍i
慢半拍i 2020-12-01 04:10

I have used QGraphicsView, QGraphicsScene classes in order to show a picture in a widget like this:

m_Scene->addPixmap(QPixmap(f         


        
4条回答
  •  情书的邮戳
    2020-12-01 04:18

    I put this here in case someone other than me runs into the same problem.

    Problem

    The GIF would not load and isValid() returns false.

    Code

    // Load animated GIF
    QMovie* movie = new QMovie("foo.gif");
    
    // Make sure the GIF was loaded correctly
    if (!movie->isValid()) 
    {
        // Something went wrong :(
    }
    
    // Play GIF
    QLabel* label = new QLabel(this);
    label->setMovie(movie);
    movie->start(); 
    

    Solution

    To solve this, I had to put Qt's GIF-plugin qgif4.dll in a folder named imageformats next to my exe to be able to use GIFs.

    The dll can be found under /plugins/imageformats/qgif4.dll.

提交回复
热议问题