PDA

View Full Version : Trouble animating line point



Qtal
16th February 2011, 19:34
Hi,

I'm trying to use the animation framework to animate a point of a line but I keep getting the error:
QPropertyAnimation: you're trying to animate a non-existing property pt1 of your QObject


class MyLine : public QGraphicsWidget {
Q_PROPERTY(QPoint pt1 READ pt1 WRITE setPt1)
public:
QPoint pt1;

MyLine() {
pt1 = *new QPoint(10, 10);
}

void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) {
painter->setPen(Qt::red);
painter->drawLine(pt1, QPoint(100, 100));
}

void setPt1(QPoint p) {
pt1.setX(p.x());
pt1.setY(p.y());
}
};

// Calling code is:
QPropertyAnimation anim(&r, "pt1");
anim.setDuration(4000);
anim.setStartValue(QPoint(10, 10));
anim.setEndValue(QPoint(100, 100));
anim.start();

Can you tell me why am I getting this error? I'm also a c++ newbie so my use of pointers and so might be wrong...

Thanks!