mirelon
17th December 2009, 00:59
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/qtanimationframework/animation.html#animations-and-the-graphics-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?
#ifndef CARDITEM_H
#define CARDITEM_H
class CardItem;
#include <QGraphicsItem>
#include <QMouseEvent>
#include <QDebug>
#include "deskview.h"
class CardItem : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
public:
CardItem();
void mousePressEvent(QGraphicsSceneMouseEvent *event);
int cid;
};
#endif // CARDITEM_H
...
CardItem* ci = new CardItem();
ci->setPixmap(rub);
ci->setPos(-100,150);
ci->setZValue(10);
graphicsView->scene()->addItem(ci);
QPropertyAnimation an(ci,"setPos");
...
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?
#ifndef CARDITEM_H
#define CARDITEM_H
class CardItem;
#include <QGraphicsItem>
#include <QMouseEvent>
#include <QDebug>
#include "deskview.h"
class CardItem : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
Q_PROPERTY(QPointF pos READ pos WRITE setPos)
public:
CardItem();
void mousePressEvent(QGraphicsSceneMouseEvent *event);
int cid;
};
#endif // CARDITEM_H
...
CardItem* ci = new CardItem();
ci->setPixmap(rub);
ci->setPos(-100,150);
ci->setZValue(10);
graphicsView->scene()->addItem(ci);
QPropertyAnimation an(ci,"setPos");
...