Simultaneously change scale and position using QPropertyAnimation [Solved]
-
Hello guys, how could I change scale and positiong of a QGraphicsItem?
What I want achive is the following scenario:
@ QPropertyAnimation* translateAnimation = new QPropertyAnimation(nav, "pos", this);
translateAnimation->setDuration(500);
translateAnimation->setEndValue(QPoint(-newX, -newY));zoomUpAnimation = new QPropertyAnimation(nav, "scale", this);
zoomUpAnimation->setDuration(500);
zoomUpAnimation->setStartValue(qreal(1));
zoomUpAnimation->setEndValue(qreal(2));QParallelAnimationGroup *group = new QParallelAnimationGroup;
group->addAnimation(zoomUpAnimation);
group->addAnimation(translateAnimation);
group->setDuration(500);group->start(QAbstractAnimation::DeleteWhenStopped);@
I wanna @ -newX, -newY@
to be the QPoint where my animation ends. -
i don't know for sure, maybe you know this... but if you don't, then this is the problem:
the x-y sytstem used in programming considers top-left corner of the screen as origin...and the valuse go right and down in +ve values... in short, the screen is the 1st quadrant of the normal x-y system(which we learn in school, which contains the positive x,y co-ords) upside down... so, you cannot use -newX,-newY unless you translate the co-ord system(which you can find in the docs, i'm sure...i've never had to use it, so i didn't ever look-up how...) -
Thank you for you reply. I am aware fo the x-y coords system. If I run the two Animation separately they run fine. When I put both in the QParallelAnimationGroup they do not work. Seems like only the scale animation is performed. Any idea?
-
maybe you should try increasing the duration to, say, 3-4 sec... probably it happens too fast for you to notice...
P.S. - i don't have any exp in animation, but i have been trying it out since i read this post...when i slowed the animation, i found that it worked; i just couldn't see it earlier :)
P.P.S. - QParallelAnimationGroup doesn't have setDuration() function...
[quote author="blackbelt" date="1340633349"]@
QParallelAnimationGroup *group = new QParallelAnimationGroup;
group->addAnimation(zoomUpAnimation);
group->addAnimation(translateAnimation);
group->setDuration(500);group->start(QAbstractAnimation::DeleteWhenStopped);@
[/quote] -
raaghuu, thank you for your reply. You are right. QParallelAnimationGroup does not have the setDuration method. Actually I managed to achieve what i want with the QTimeLine. When the
QTimeLine::valueChanged callback is called I apply to the object I want to scale and move the following transformation:@void
QTimeLine::valueChanged(qreal step)
{QRectF r = item->boundingRect();
currentScale = 1 + 1 * step;
qreal dx = r.width() / 2.0;
qreal dy = r.height() / 2.0;
qreal scrollDx = scrollInXstep;
qreal scrollDy = scrollInYstep;
item->setTransform(QTransform()
.translate(dx ,dy)
.scale(currentScale, currentScale)
.translate(-dx+scrollDx, -dy+scrollDy));}@
hope it helps somebody else
-
you should add [SOLVED] to your thread title then