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