PDA

View Full Version : QPainter and Animation



miker
29th January 2006, 08:28
Hi

I am currently trying to write a small card game in Qt 4.
I am using a QWidget with the paint method overidden for drawing.

I want to be able to drag and drop cards. I can use mouseDown and mouseMove and keep painting the card making sure I have the old background to paint back when the card moves. Or is there a better way? Problem: How do I paint from the mousemove event?

I also want to be able to animate the cards moving across the board. Im not sure how to do this as the animation would have to be some kind of loop and I dont know how to paint outside of being in the paint method. Would my loop just update some co-ordinates somewhere and call a repaint and the paint method take care of it?

If everything were to be done in the paint method its going to get pretty large. right?

Thanks.

Mike

jacek
29th January 2006, 13:53
You could try Q3Canvas.

axeljaeger
29th January 2006, 17:33
The proper way to draw something is to put some data to paint in variables, fire a paintEvent using update() and then paint in the generated paintEvent(). If you want to have a animation, you can connect a timer's timeout()-signal to QWidget::update().

miker
29th January 2006, 20:58
The proper way to draw something is to put some data to paint in variables, fire a paintEvent using update() and then paint in the generated paintEvent(). If you want to have a animation, you can connect a timer's timeout()-signal to QWidget::update().

Wouldnt that be awfully slow redrawing everything when all that is changed is the position of one object?

I had an idea that I could use an offscreen QPixmap and make the paint method just draw that to the screen.

Which is faster to draw onto a QWidget. QPixmap or QImage?, I read somewhere about one being converted to the other?

wysota
30th January 2006, 04:09
Wouldnt that be awfully slow redrawing everything when all that is changed is the position of one object?

Who said to redraw everything? :) With paint events you get information which parts of the display changed and you need to redraw only those parts, you can leave the rest untouched.