Solved Animated gif in window play once
-
Hello.
I want to play an animated gif and make it stop at the last picture.
QMovie *title = new QMovie("windowLogs/myTitle.gif"); QLabel *titleLabel = new QLabel(&mainWindow); titleLabel->setMovie(title); titleLabel->move(13, 13); title->start();
Using this code, the movie restarts again and again...
Is there a simple way to make the loop stop?
Thanks a lot.
-
You can try using the object's finish signal and connect it to the object's stop slot.
-
Thanks.
I tried it like this:
QMovie *title = new QMovie("windowLogs/myTitle.gif"); QLabel *titleLabel = new QLabel(&mainWindow); titleLabel->setMovie(title); titleLabel->move(13, 13); title->start(); connect(title, SIGNAL(finished()), title, QMovie::stop());
But an error message comes:
cannot call member function 'void QMovie::stop()' without object
connect(title, SIGNAL(finished()), title, QMovie::stop()); ^I watched different examples but can't figure out what'sgoing wrong.
-
@Shodan said in Animated gif in window play once:
connect(title, SIGNAL(finished()), title, QMovie::stop());
Should that not be
connect(title, SIGNAL(finished()), title, SLOT(stop()));
-
Great!
Thanks for the help.Programming is pretty new for me, and many examples way to complicate yet...
Like this it works like a charm:
QObject::connect(title, SIGNAL(finished()), title, SLOT(stop()));
-
Obviously it is also possible to disable or enable looping for animated gif files (and also set a repeat count) with free editors like "microsoft gif animator".