Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Simultaneously change scale and position using QPropertyAnimation [Solved]
Forum Updated to NodeBB v4.3 + New Features

Simultaneously change scale and position using QPropertyAnimation [Solved]

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 5.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    blackbelt
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raaghuu
      wrote on last edited by
      #2

      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...)

      1 Reply Last reply
      0
      • B Offline
        B Offline
        blackbelt
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          raaghuu
          wrote on last edited by
          #4

          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]

          1 Reply Last reply
          0
          • B Offline
            B Offline
            blackbelt
            wrote on last edited by
            #5

            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 = scrollInY
            step;
            item->setTransform(QTransform()
            .translate(dx ,dy)
            .scale(currentScale, currentScale)
            .translate(-dx+scrollDx, -dy+scrollDy));

            }@

            hope it helps somebody else

            1 Reply Last reply
            0
            • R Offline
              R Offline
              raaghuu
              wrote on last edited by
              #6

              you should add [SOLVED] to your thread title then

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved