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. How to set the duration of a QVariantAnimation constant to different values?

How to set the duration of a QVariantAnimation constant to different values?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 398 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.
  • K Offline
    K Offline
    Kattia
    wrote on last edited by
    #1

    How to get a constant animation duration time, independent of how small/bigger the frame size is?

    For example, when startSize is 900x900, the animation duration time should be the same than when the startSize be 100x100

    void ThumbnailFrame::resetSize()
    {
        QVariantAnimation* ani = new QVariantAnimation;
    
        QSize startSize = thumbnailFrame->size();
        QSize endSize(p_ui->displayWidth->text().toInt(),
            p_ui->displayHeight->text().toInt());
    
        qreal distance = qSqrt(qPow(startSize.width() - endSize.width(), 2) 
            + qPow(startSize.height() - endSize.height(), 2));
        int duration = static_cast<int>(distance / 2); // factor
    
        ani->setEasingCurve(QEasingCurve::Type::Linear);
        ani->setDuration(duration);
        ani->setStartValue(startSize);
        ani->setEndValue(endSize);
    
        connect(ani, &QVariantAnimation::valueChanged, thumbnailFrame,
            [=](const QVariant& value)
        {
            thumbnailFrame->setFixedSize(value.toSize());
        });
    
        ani->start(QAbstractAnimation::DeleteWhenStopped);
    }
    

    I tried

    qreal distance = qSqrt(qPow(startSize.width() - endSize.width(), 2) 
            + qPow(startSize.height() - endSize.height(), 2));
        int duration = static_cast<int>(distance / 2); // factor
    

    But it aint resulting in a constant duration speed independent of the frame start/end size

    Pl45m4P 2 Replies Last reply
    0
    • Pl45m4P Pl45m4

      Hi @Kattia ,

      I think you're mixing two approaches.

      How to get a constant animation duration time, independent of how small/bigger the frame size is?

      Here you are asking for "constant time", independent of covered distance, which needs to result in variable speeds.

      But it aint resulting in a constant duration speed independent of the frame start/end size

      and here you are saying, that you expect the above approach to have constant speed, no matter if you animate from 900x900 or 100x100 to whatever size.

      How should this work?! :)
      You can't drive 1h with 100km/h twice and expect to cover 100km in the first and 500km in the second run :))

      It's either... or...
      Either you set a fixed duration and let the QVariantAnimation calculate the step-size from start to end ("speed").
      Or you calculate the step-size ("speed") on your own before and set the resulting duration time.

      K Offline
      K Offline
      Kattia
      wrote on last edited by
      #3

      @Pl45m4 yes im a bit confused, but what im trying is to make the animation have the same duration independent of the size

      1 Reply Last reply
      1
      • K Kattia

        How to get a constant animation duration time, independent of how small/bigger the frame size is?

        For example, when startSize is 900x900, the animation duration time should be the same than when the startSize be 100x100

        void ThumbnailFrame::resetSize()
        {
            QVariantAnimation* ani = new QVariantAnimation;
        
            QSize startSize = thumbnailFrame->size();
            QSize endSize(p_ui->displayWidth->text().toInt(),
                p_ui->displayHeight->text().toInt());
        
            qreal distance = qSqrt(qPow(startSize.width() - endSize.width(), 2) 
                + qPow(startSize.height() - endSize.height(), 2));
            int duration = static_cast<int>(distance / 2); // factor
        
            ani->setEasingCurve(QEasingCurve::Type::Linear);
            ani->setDuration(duration);
            ani->setStartValue(startSize);
            ani->setEndValue(endSize);
        
            connect(ani, &QVariantAnimation::valueChanged, thumbnailFrame,
                [=](const QVariant& value)
            {
                thumbnailFrame->setFixedSize(value.toSize());
            });
        
            ani->start(QAbstractAnimation::DeleteWhenStopped);
        }
        

        I tried

        qreal distance = qSqrt(qPow(startSize.width() - endSize.width(), 2) 
                + qPow(startSize.height() - endSize.height(), 2));
            int duration = static_cast<int>(distance / 2); // factor
        

        But it aint resulting in a constant duration speed independent of the frame start/end size

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #2

        Hi @Kattia ,

        I think you're mixing two approaches.

        How to get a constant animation duration time, independent of how small/bigger the frame size is?

        Here you are asking for "constant time", independent of covered distance, which needs to result in variable speeds.

        But it aint resulting in a constant duration speed independent of the frame start/end size

        and here you are saying, that you expect the above approach to have constant speed, no matter if you animate from 900x900 or 100x100 to whatever size.

        How should this work?! :)
        You can't drive 1h with 100km/h twice and expect to cover 100km in the first and 500km in the second run :))

        It's either... or...
        Either you set a fixed duration and let the QVariantAnimation calculate the step-size from start to end ("speed").
        Or you calculate the step-size ("speed") on your own before and set the resulting duration time.


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        K 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          Hi @Kattia ,

          I think you're mixing two approaches.

          How to get a constant animation duration time, independent of how small/bigger the frame size is?

          Here you are asking for "constant time", independent of covered distance, which needs to result in variable speeds.

          But it aint resulting in a constant duration speed independent of the frame start/end size

          and here you are saying, that you expect the above approach to have constant speed, no matter if you animate from 900x900 or 100x100 to whatever size.

          How should this work?! :)
          You can't drive 1h with 100km/h twice and expect to cover 100km in the first and 500km in the second run :))

          It's either... or...
          Either you set a fixed duration and let the QVariantAnimation calculate the step-size from start to end ("speed").
          Or you calculate the step-size ("speed") on your own before and set the resulting duration time.

          K Offline
          K Offline
          Kattia
          wrote on last edited by
          #3

          @Pl45m4 yes im a bit confused, but what im trying is to make the animation have the same duration independent of the size

          1 Reply Last reply
          1
          • K Kattia

            How to get a constant animation duration time, independent of how small/bigger the frame size is?

            For example, when startSize is 900x900, the animation duration time should be the same than when the startSize be 100x100

            void ThumbnailFrame::resetSize()
            {
                QVariantAnimation* ani = new QVariantAnimation;
            
                QSize startSize = thumbnailFrame->size();
                QSize endSize(p_ui->displayWidth->text().toInt(),
                    p_ui->displayHeight->text().toInt());
            
                qreal distance = qSqrt(qPow(startSize.width() - endSize.width(), 2) 
                    + qPow(startSize.height() - endSize.height(), 2));
                int duration = static_cast<int>(distance / 2); // factor
            
                ani->setEasingCurve(QEasingCurve::Type::Linear);
                ani->setDuration(duration);
                ani->setStartValue(startSize);
                ani->setEndValue(endSize);
            
                connect(ani, &QVariantAnimation::valueChanged, thumbnailFrame,
                    [=](const QVariant& value)
                {
                    thumbnailFrame->setFixedSize(value.toSize());
                });
            
                ani->start(QAbstractAnimation::DeleteWhenStopped);
            }
            

            I tried

            qreal distance = qSqrt(qPow(startSize.width() - endSize.width(), 2) 
                    + qPow(startSize.height() - endSize.height(), 2));
                int duration = static_cast<int>(distance / 2); // factor
            

            But it aint resulting in a constant duration speed independent of the frame start/end size

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #4

            @Kattia said in How to set the duration of a QVariantAnimation constant to different values?:

            ani->setDuration(duration);

            If you set this to the time you need, it should be enough.
            QVariantAnimation transforms start to end using the curve function given here

            ani->setEasingCurve(QEasingCurve::Type::Linear);

            in a constant time interval.


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            K 1 Reply Last reply
            0
            • Pl45m4P Pl45m4

              @Kattia said in How to set the duration of a QVariantAnimation constant to different values?:

              ani->setDuration(duration);

              If you set this to the time you need, it should be enough.
              QVariantAnimation transforms start to end using the curve function given here

              ani->setEasingCurve(QEasingCurve::Type::Linear);

              in a constant time interval.

              K Offline
              K Offline
              Kattia
              wrote on last edited by
              #5

              Thankyou! you're correct i was testing it wrong, thats why i was getting a different animation time, sorry my bad!

              1 Reply Last reply
              0
              • K Kattia has marked this topic as solved on

              • Login

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