Results 1 to 5 of 5

Thread: QPainter and Animation

  1. #1
    Join Date
    Jan 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QPainter and Animation

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPainter and Animation

    You could try Q3Canvas.

  3. #3
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: QPainter and Animation

    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().
    It's nice to be important but it's more important to be nice.

  4. #4
    Join Date
    Jan 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPainter and Animation

    Quote Originally Posted by axeljaeger
    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?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPainter and Animation

    Quote Originally Posted by miker
    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.

  6. The following user says thank you to wysota for this useful post:


Similar Threads

  1. Fading effect on QPainter fillrect()
    By smarinr in forum Qt Programming
    Replies: 7
    Last Post: 29th April 2008, 21:57

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.