Results 1 to 3 of 3

Thread: Animation and QGraphics

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

    Default Animation and QGraphics

    I'm using the graphics objects to display boxes with arrows between them. I want animation on those arrows/lines that starts at one end and goes to the other.

    The animation works great when the start and end locations of the arrow don't change during QTimeLine execution, i.e. I leave the view static.
    But since the user can drag the boxes around (and thus I redraw the arrows to follow) I need to reset the start and end position inside the QGraphicsItemAnimation so the animation matches the new arrow line.

    I tried to update the start and end locations in the paint method of the Arrow object but that just makes the animation go crazy (it flips randomly all over the place). I assume it's because I changed the animation positions when the QTimeLine object was in the RUNNING state.

    Qt Code:
    1. void Arrow::paint(QPainter *painter,
    2. {
    3. ...
    4. ///update the arrow to have a new source and destination, draw arrow, etc
    5. ...
    6.  
    7. if (mAnimate)
    8. {
    9. mAnimationObj->setPosAt(0, mSourcePoint);
    10. mAnimationObj->setPosAt(1, mDestPoint);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 


    How should I dynamically change the QGraphicsItemAnimation start and end positions (0 and 1)?

    For the end product, I want the user to be able to drag the boxes around, have the arrows follow (which currently works) as well as have the animation continue along the new arrow route.

    If that isn't possible, then I need to figure out some way to capture the dragging and stop the arrow animation until the user releases and then I guess reset it...?

    Thanks

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

    Default Re: Animation and QGraphics

    QGraphicsItemAnimation::clear() the animation, optionally stop the timeline and restart it after setting new properties for the animation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Posts
    17
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Animation and QGraphics

    Adding the "clear" before resetting the positions in "paint" worked perfectly, thanks.

Tags for this Thread

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.