PDA

View Full Version : How to insert an animated picture (GIF) in a QLabel



AngiSad
13th January 2010, 14:58
I have been trying to insert an animated picture GIF in a QLabel. I searched in Google to see how to do it (I am a newbie )
I used this code:



#include <QtGui>

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QLabel w;

// On crée une vidéo. Ici, c'est un GIF
QMovie movie("c:/Mickey-11.gif");
// On l'associe à un label
w.setMovie (&movie);
// On lance la vidéo
movie.start ();

w.show();
return app.exec();
}


(from http://qt.developpez.com/faq/?page=animation#gif_anime)

but it is not working. They mentioned compiling the GIF plugin but I didn't know how to do it.

Thanx for your help

high_flyer
13th January 2010, 16:31
You will need to have Qt with GIF support.
Run configure in your Qt source folder to see if your Qt is configured with GIF support.
If not, you will have to run configure with the correct flags, and rebuild your Qt installation.
configure prints help on how to use it.


If your Qt does support GIF, then it could be that your GIF object only iterates once through the animation, or that the movie is not valid.
Call:


bool bValid = movie.isValid().
int iLoopCount = movie.loopCount();


to see how many times your movie loops - it could be that its fery short, and by the time you get to see the label it has ended playing.

It would be better if you put the whole code in a widget class, this way you could connect various signals from the movie objects to slots in your widget class, and know much better what is going on.

Be sure to read the QMovie documentation.