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. QVariantAnimation: how many "steps" given a duration ?

QVariantAnimation: how many "steps" given a duration ?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 496 Views
  • 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.
  • D Offline
    D Offline
    dextermagnific
    wrote on last edited by
    #1

    Hi all,

    I'm using QVariantAnimation to animate some QGraphicsItems and I'd like to have control over the number of "valueChanged()" signals that will be emitted given some duration.
    I'd like to minimize the number of redraws. For example, I'd like to have no more than 5 redraws (of course it depends on the difference between start and end value, but I'd like to clip it to a maximum of 5).

    Is there some way to set this or another way to simulate it ? I think I can ignore some valueChanged() but for this I need to know the value of the "qreal progress" so I can choose at which time to update the drawing.

    Thanks.

    raven-worxR 1 Reply Last reply
    0
    • D dextermagnific

      Hi all,

      I'm using QVariantAnimation to animate some QGraphicsItems and I'd like to have control over the number of "valueChanged()" signals that will be emitted given some duration.
      I'd like to minimize the number of redraws. For example, I'd like to have no more than 5 redraws (of course it depends on the difference between start and end value, but I'd like to clip it to a maximum of 5).

      Is there some way to set this or another way to simulate it ? I think I can ignore some valueChanged() but for this I need to know the value of the "qreal progress" so I can choose at which time to update the drawing.

      Thanks.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @dextermagnific
      if you want to have exactly lets say 5 steps, why not simply starting a QVariantAnimation from 1 to 5 in a given time and do what you want with it on the valueChanged() signal?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dextermagnific
        wrote on last edited by
        #3

        Well I'm currently interpolating a QColor, and QVariantAnimation is here to hide the details of this interpolation.
        Otherwise I need to call manually the QColor interpolator, which is not part of the API.

        raven-worxR 1 Reply Last reply
        0
        • D dextermagnific

          Well I'm currently interpolating a QColor, and QVariantAnimation is here to hide the details of this interpolation.
          Otherwise I need to call manually the QColor interpolator, which is not part of the API.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @dextermagnific
          still possible with a second animation (for example your current animation) and call

          stepAnim->setStartValue( 0 );
          stepAnim->setEndValue( 5 );
          connect(stepAnim, &QVariantAnimation::valueChanged, this, [this](const QVariant &value) {
              colorAnim->keyValueAt( 1.0/stepAnim->endValue().toInt() * value.toInt() );
          });
          

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • D Offline
            D Offline
            dextermagnific
            wrote on last edited by
            #5

            Interesting approach.
            But I think keyValueAt() will only return a non null QVariant if a prior setKeyValueAt() has been issued, right ?

            raven-worxR 1 Reply Last reply
            0
            • D dextermagnific

              Interesting approach.
              But I think keyValueAt() will only return a non null QVariant if a prior setKeyValueAt() has been issued, right ?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #6

              @dextermagnific
              yes, my example is incorrect.

              Here you go:

              stepAnim->setStartValue( 0 );
              stepAnim->setEndValue( 5 );
              
              //QPropertyAnimation* interpolatorAnim
                 interpolatorAnim->setEasingCurve(QEasingCurve::Linear);
                 interpolatorAnim->setDuration(stepAnim->endValue());
                 interpolatorAnim->setKeyValueAt(0, fromColor);
                 interpolatorAnim->setKeyValueAt(1, toColor);
              
              connect(stepAnim, &QVariantAnimation::valueChanged, this, [this](const QVariant &value) {
                   interpolatorAnim->setCurrentTime( value.toInt() );
                   QColor color = interpolatorAnim->currentValue().value<QColor>();
                   ...
              });
              

              You can encapsulate this code in a custom ColorAnimation class if you like to make it more reusable.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              2
              • D Offline
                D Offline
                dextermagnific
                wrote on last edited by
                #7

                Thanks. Sounds good. "main" interpolator would be the one doing 0..5 and we get colors from "sub" interpolators.
                This is especially suitable for my use case in which I animate multiple QColors for a single item (outline, fill, text, ....). This will avoid updating drawing each time one of these change. Now I can group multiple changes (outline, fill, text) into one change only.

                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