Results 1 to 5 of 5

Thread: Animation of QGraphicsItem in QGraphicsView

  1. #1
    Join Date
    Dec 2009
    Location
    Bratislava, Slovakia
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Animation of QGraphicsItem in QGraphicsView

    I want to make an animation with QGraphicsItem. I know it is possible with QGraphicsItemAnimation, but I want to join more animations with QSequentialAnimationGroup. In order to do this, child animations have to inherit QAbstractAnimation. In docs, there is an example how to do this with QPropertyAnimation. The key to victory is macro Q_PROPERTY as explained here: http://doc.trolltech.com/solutions/4...view-framework.

    I tried to implement. It compiled succesfully, but in runtime, when creating QPropertyAnimation, the error appeared:

    QPropertyAnimation: you're trying to animate a non-existing property setPos of your QObject.

    But it is declared in the macro, so where is the problem?

    Qt Code:
    1. #ifndef CARDITEM_H
    2. #define CARDITEM_H
    3.  
    4. class CardItem;
    5.  
    6. #include <QGraphicsItem>
    7. #include <QMouseEvent>
    8. #include <QDebug>
    9. #include "deskview.h"
    10.  
    11. class CardItem : public QObject, public QGraphicsPixmapItem
    12. {
    13. Q_OBJECT
    14. Q_PROPERTY(QPointF pos READ pos WRITE setPos)
    15. public:
    16. CardItem();
    17. void mousePressEvent(QGraphicsSceneMouseEvent *event);
    18. int cid;
    19. };
    20.  
    21. #endif // CARDITEM_H
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. ...
    2. CardItem* ci = new CardItem();
    3. ci->setPixmap(rub);
    4. ci->setPos(-100,150);
    5. ci->setZValue(10);
    6. graphicsView->scene()->addItem(ci);
    7. QPropertyAnimation an(ci,"setPos");
    8. ...
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Animation of QGraphicsItem in QGraphicsView

    Quote Originally Posted by mirelon View Post
    Qt Code:
    1. QPropertyAnimation an(ci,"setPos");
    To copy to clipboard, switch view to plain text mode 
    You must use the name of the property!
    Qt Code:
    1. QPropertyAnimation an(ci,"pos");
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to Lykurg for this useful post:

    mirelon (17th December 2009)

  4. #3
    Join Date
    Dec 2009
    Location
    Bratislava, Slovakia
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Animation of QGraphicsItem in QGraphicsView

    Thank you very much, now I am going on with my project. But another question arises. When some animation is going near the border of graphicsView, it automatically moves the whole scene and the scrollbars appear.

    I searched for it, but I dont have correct keywords for it, i think it should be some property of graphics view. I want something like the coordinate system in graphics view is fixed, so it dont move on its own.

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Animation of QGraphicsItem in QGraphicsView

    Then you have to set a sceen rect by your own. Then Qt wont adjust the size automatically. And you might want to positioning the scene on the top rather than in the middle.

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

    mirelon (19th December 2009)

  7. #5
    Join Date
    Dec 2009
    Location
    Bratislava, Slovakia
    Posts
    11
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Animation of QGraphicsItem in QGraphicsView

    Ok, i managed to do it...but not while i want to enable resizing of the window.
    I have:

    main window
    central widget (vertical layout, so i can set size policy)
    graphics view
    graphics scene

    and when i resize main window, the graphics view should be also resized
    it can be done with size policy "expanding"

    but i also want to have graphics scene fixed 800*600 (i have hard-coded positions of animations in it, so it must be this size), so resizing will zoom the scene.

    how can i do that?

Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 21:50
  2. Replies: 5
    Last Post: 31st December 2010, 12:49
  3. Multiple inheritance of QGraphicsView and QGraphicsItem
    By cookie1909 in forum Qt Programming
    Replies: 9
    Last Post: 15th May 2009, 19:02
  4. QGraphicsView animation issues?
    By m41n1 in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2008, 08:48
  5. (QT4.2-RC1) QGraphicsScene QGraphicsView QGraphicsItem
    By antonio.r.tome in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 11:56

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.