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:
MyLine() {
}
painter->setPen(Qt::red);
painter
->drawLine
(pt1,
QPoint(100,
100));
}
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();
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();
To copy to clipboard, switch view to plain text mode
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!
Bookmarks