QPropertyAnimation of a QGraphicsTextItem with a frame make the text shaky
-
I'm animating a QGraphicsTextItem that I've added a frame around. During the animation the text seems to shake slightly inside the frame, which is very annoying.
An example code:
class MovingFrameText : public QGraphicsTextItem { Q_OBJECT; public: MovingFrameText( ): QGraphicsTextItem(0) { setPlainText ( "Shaky "); QFont f = font(); f.setPixelSize(40); setFont(f); setFlags(QGraphicsItem::ItemIsMovable); } QRectF boundingRect() const { return QGraphicsTextItem::boundingRect().adjusted(-2,-2,+2,+2); } void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget) { QGraphicsTextItem::paint(painter,option,widget); painter->setPen(Qt::black); painter->drawRect(boundingRect()); } }; int main(int argc, char *argv[]) { QApplication app(argc,argv); MovingFrameText t; t.setPos(640,680); QGraphicsScene scene; scene.addItem(&t); QGraphicsView view(&scene); view.resize(640, 680); view.show(); auto moveAnimation = new QPropertyAnimation( &t, "pos" ); moveAnimation->setDuration( 10000 ); moveAnimation->setStartValue( QPointF(640, 680) ); moveAnimation->setEndValue( QPointF(0, 0) ); moveAnimation->setEasingCurve( QEasingCurve::Linear ); moveAnimation->start(QAbstractAnimation::DeleteWhenStopped); return app.exec(); }Is there any way to fix this and make the animation smooth? I've tried to find a solution online for some time now, and I can't seem to find any.
-