PDA

View Full Version : Widget for Animating a Series of Images



cpsmusic
27th June 2010, 13:09
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

tbscope
27th June 2010, 14:35
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.

numbat
27th June 2010, 15:16
AnimatedLabel widget (http://www.qtcentre.org/threads/26911-PNG-based-animation)

cpsmusic
28th June 2010, 01:10
AnimatedLabel widget (http://www.qtcentre.org/threads/26911-PNG-based-animation)

Thanks, that's just what I was looking for.

Cheers,

Chris

cpsmusic
28th June 2010, 14:33
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

Talei
28th June 2010, 15:04
For example QImage work with non GUI threads.

cpsmusic
30th June 2010, 03:17
Is there a simple example showing how to use QImage anywhere?

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

Talei
30th June 2010, 06:44
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:

//code in non GUI thread
QImage thumb, tmp;
thumb = (tmp.scaled( sizeW, sizeH ).scaled( sizeW, sizeH, Qt::KeepAspectRatio, Qt::SmoothTransformation ));

To display QImage in QLabel use something like this:

QImage tmp;
ui->label->setPixmap( QPixmap().fromImage( tmp ) );