Results 1 to 8 of 8

Thread: Widget for Animating a Series of Images

  1. #1
    Join Date
    Jun 2010
    Posts
    30
    Thanks
    7

    Default Widget for Animating a Series of Images

    Hi,

    I need to animate a series of images. There seems to be quite a few options for doing this. What would be the best widget to start with?

    The program I'm developing will control when each of the animated images is updated. As such, what I need to do is load a series of images, draw one to the display, draw the next one to an offscreen bufer, swap the images, and so on. I've worked with OpenGL so that's the sort of approach I was thinking of.

    Cheers,

    Chris

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Widget for Animating a Series of Images

    You can make it yourself very easy by using just a qlabel and a timer or timeline.

    If you use a timeline, set the duration and the amount of frames.
    Then, when you get a framechanged signal, update the buffer and draw the buffer on the label.

    As an alternative, you can use QGraphicsView. But this takes a view, a scene and some items to do the same as you can with just a label.

  3. #3
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget for Animating a Series of Images


  4. #4
    Join Date
    Jun 2010
    Posts
    30
    Thanks
    7

    Thumbs up Re: Widget for Animating a Series of Images

    Quote Originally Posted by numbat View Post
    Thanks, that's just what I was looking for.

    Cheers,

    Chris

  5. #5
    Join Date
    Jun 2010
    Posts
    30
    Thanks
    7

    Question Re: Widget for Animating a Series of Images

    I've run into a problem using the AnimatedLabel class (see above). I'm updating the label's image outside of the GUI thread. I understand that this isn't supported by QPixmap. Here's the error message I'm getting:

    QPixmap: It is not safe to use pixmaps outside the GUI thread

    What is an alternative way to display and animate a series of images (outside the GUI thread)?

    Cheers,

    Chris

  6. #6
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Widget for Animating a Series of Images

    For example QImage work with non GUI threads.

  7. #7
    Join Date
    Jun 2010
    Posts
    30
    Thanks
    7

    Default Re: Widget for Animating a Series of Images

    Is there a simple example showing how to use QImage anywhere?

    I understand what QImage is, but how do I actually display it?

  8. #8
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Widget for Animating a Series of Images

    You can use QImage basically the same way as QPixmap. Main difference between these two classes is that QPixamp is stored in the server side (i.e. xwindow manager side) while QImage is independent. Also QPixmap is optymized for display and QImage optymized for I/O and pixel manipulation. That's why You can't use QPixmap in the non GUI thread.
    About usage, QImage is essentially used same as QPixmap, but depending on what You want to use it for sometimes conversion is needed to QPixmap.
    For example, I used QImage to create thumbnails of the images in another thread like:
    Qt Code:
    1. //code in non GUI thread
    2. QImage thumb, tmp;
    3. thumb = (tmp.scaled( sizeW, sizeH ).scaled( sizeW, sizeH, Qt::KeepAspectRatio, Qt::SmoothTransformation ));
    To copy to clipboard, switch view to plain text mode 
    To display QImage in QLabel use something like this:
    Qt Code:
    1. QImage tmp;
    2. ui->label->setPixmap( QPixmap().fromImage( tmp ) );
    To copy to clipboard, switch view to plain text mode 

  9. The following user says thank you to Talei for this useful post:

    cpsmusic (1st July 2010)

Similar Threads

  1. Raw Images on Qt Widget
    By Ratheendrans in forum Qt Programming
    Replies: 11
    Last Post: 16th August 2010, 20:44
  2. Replies: 1
    Last Post: 16th April 2009, 16:12
  3. How can I change widget images and layouts?
    By sendyou in forum Qt Programming
    Replies: 1
    Last Post: 20th August 2008, 11:07
  4. Widget to display images and text ?
    By probine in forum Qt Tools
    Replies: 4
    Last Post: 9th October 2006, 20:49
  5. Animating "any" widget?!?
    By nupul in forum Qt Programming
    Replies: 3
    Last Post: 10th April 2006, 07:06

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.