我有一堆QRects和QGraphicsScene中的一些文本,我試圖用QPropertyAnimation進行動畫製作。動畫文字工作正常,但QRects不工作,因爲他們無法轉換爲QGraphicsObject用QPropertyAnimation動畫化QRect
這工作完全
QPropertyAnimation *a = new QPropertyAnimation(this);
a->setTargetObject(items[size.x()*size.y()-1-aa]->toGraphicsObject()); //text
a->setPropertyName("pos");
a->setDuration(animationLength);
a->setStartValue(items[size.x()*size.y()-1-aa]->pos());
a->setEndValue(newTextPos);
a->setEasingCurve(easingCurve);
a->start(QAbstractAnimation::DeleteWhenStopped);
但是,這不,因爲項目[2 * size.x() * size.y() - 2-aa] - > toGraphicsObject()返回一個空指針。
QPropertyAnimation *a = new QPropertyAnimation(this);
a->setTargetObject(items[2*size.x()*size.y()-2-aa]->toGraphicsObject()); //rect
a->setPropertyName("pos");
a->setDuration(animationLength);
a->setStartValue(items[2*size.x()*size.y()-2-aa]->pos());
a->setEndValue(newRectPos);
a->setEasingCurve(easingCurve);
a->start(QAbstractAnimation::DeleteWhenStopped);
有沒有辦法解決這個問題?
QRect不是一個圖形項目,你的意思是QGraphicsRectItem? –
恩,也許吧。我添加了與QGraphicsScene :: addRect – Ben