Results 1 to 3 of 3

Thread: question regards how to use animation framework in graphics view items

  1. #1
    Join Date
    Jan 2009
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post

    Question question regards how to use animation framework in graphics view items

    I want to animate an graphic item in graphics view, I want to this item moving, rotating around y axis, scaling at the same

    time. I want to use graphicsview framework and animation framework.

    according to the animation framework manual, if I want to animate the graphic view item, I should inhert from Object, and

    declare many metaObject properties for the animation framework.

    1, declare a class with many animation properties.
    Qt Code:
    1. class GraphicItem: public QObject, public QGraphicsRectItem
    2. {
    3. Q_OBJECT
    4. Q_PROPERTY(QPointF pos READ pos WRITE setPos) //for moving property
    5. Q_PROPERTY(float scaleFactor READ scaleFactor WRITE setScaleFactor) //for scaling
    6. Q_PROPERTY(int rotateAngle READ rotateAngle WRITE setRotateAngle) //for rotating
    7.  
    8. /*some functions*/
    9.  
    10. //below is setter and getter funs of the properties.
    11. float scaleFactor() const;
    12. void setScaleFactor(float);
    13. int rotateAngle() const;
    14. void setRotateAngle(int);
    15.  
    16. private:
    17. /*some variables declaration*/
    18. };
    To copy to clipboard, switch view to plain text mode 
    2. getter and setter funcs are like below, and the pos property has pos getter and setPos setter automatically.
    Qt Code:
    1. float GraphicItem::scaleFactor() const
    2. {
    3. return factor;
    4. }
    5.  
    6. void GraphicItem::setScaleFactor(float scale)
    7. {
    8. factor = scale;
    9. setScale( scale ); //this can scaling the item
    10. }
    11.  
    12. int GraphicItem::rotateAngle() const
    13. {
    14. return angle;
    15. }
    16. void GraphicItem::setRotateAngle(int a)
    17. {
    18. angle = a;
    19. setTransform(QTransform().rotate(a, Qt::YAxis)); //can rotating the item around y axis
    20. }
    To copy to clipboard, switch view to plain text mode 
    3, use animation framework to animate the item. item0 is a instance of graphicItem object.

    Qt Code:
    1. QPropertyAnimation animation(item0, "pos");
    2. animation.setDuration(1000);
    3. animation.setStartValue(QPointF(-200,0));
    4. animation.setEndValue(QPointF(-400,0));
    5.  
    6. animation.start();
    To copy to clipboard, switch view to plain text mode 

    I desire it can moving from point (-200,0) to point (-400,0), but it can't moving at all, the same to the other two properites

    scaleFactor and rotateAngle.

    what's wrong with my code?

    please give me some hints, any suggestion is highly appreciated.

    thanks

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: question regards how to use animation framework in graphics view items

    Did you have a look at examples in Qt Demos ?
    From 4.6.x onwards you have examples for Animation framework. Check them out... especially the animated tiles example

  3. #3
    Join Date
    Jan 2009
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: question regards how to use animation framework in graphics view items

    if "QPropertyAnimation animation(item0, "pos");" is in a function then it is auto destroyed at the function end.

    it works! now

    thanks

Similar Threads

  1. Using the animation framework with graphic items
    By technoViking in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2009, 02:38
  2. Can you use the animation framework on graphic items?
    By technoViking in forum Qt Programming
    Replies: 1
    Last Post: 6th November 2009, 19:34
  3. Problem about Graphics View Framework
    By FinderCheng in forum Qt Programming
    Replies: 5
    Last Post: 3rd November 2009, 08:16
  4. Problem with Graphics View Framework
    By Disperato in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2009, 20:44
  5. Issues with the Graphics View Framework
    By lni in forum Qt Programming
    Replies: 8
    Last Post: 26th April 2009, 14:13

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.