Results 1 to 2 of 2

Thread: How to insert an animated picture (GIF) in a QLabel

  1. #1
    Join Date
    Jan 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to insert an animated picture (GIF) in a QLabel

    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:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char* argv[])
    4. {
    5. QApplication app(argc, argv);
    6. QLabel w;
    7.  
    8. // On crée une vidéo. Ici, c'est un GIF
    9. QMovie movie("c:/Mickey-11.gif");
    10. // On l'associe à un label
    11. w.setMovie (&movie);
    12. // On lance la vidéo
    13. movie.start ();
    14.  
    15. w.show();
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 
    (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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to insert an animated picture (GIF) in a QLabel

    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:
    Qt Code:
    1. bool bValid = movie.isValid().
    2. int iLoopCount = movie.loopCount();
    To copy to clipboard, switch view to plain text mode 

    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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Insert picture in a form using label
    By cwnelatury in forum Newbie
    Replies: 14
    Last Post: 18th March 2010, 23:43
  2. Replies: 4
    Last Post: 13th January 2010, 17:05
  3. Dynamic Animated QLabel
    By patrik08 in forum Qt-based Software
    Replies: 0
    Last Post: 30th May 2008, 18:38
  4. Pb with animated gif on Mac os
    By mourad in forum Qt Programming
    Replies: 0
    Last Post: 17th April 2008, 13:38
  5. Replies: 3
    Last Post: 4th June 2007, 09:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.