QEasingCurve Class Reference

The QEasingCurve class provides easing curves for controlling animation.

  1. #include <QEasingCurve>

This class was introduced in Qt 4.6.

Detailed Description

The QEasingCurve class provides easing curves for controlling animation.

Easing curves describe a function that controls how the speed of the interpolation between 0 and 1 should be. Easing curves allow transitions from one value to another to appear more natural than a simple constant speed would allow. The QEasingCurve class is usually used in conjunction with the QVariantAnimation and QPropertyAnimation classes but can be used on its own. It is usually used to accelerate the interpolation from zero velocity (ease in) or decelerate to zero velocity (ease out). Ease in and ease out can also be combined in the same easing curve.

To calculate the speed of the interpolation, the easing curve provides the function valueForProgress(), where the progress argument specifies the progress of the interpolation: 0 is the start value of the interpolation, 1 is the end value of the interpolation. The returned value is the effective progress of the interpolation. If the returned value is the same as the input value for all input values the easing curve is a linear curve. This is the default behaviour.

For example,

  1. QEasingCurve easing(QEasingCurve::InOutQuad);
  2.  
  3. for(qreal t = 0.0; t < 1.0; t+=0.1)
  4.     qWarning() << "Effective progress" << t << " is
  5.               << easing.valueForProgress(t);

will print the effective progress of the interpolation between 0 and 1.

When using a QPropertyAnimation, the associated easing curve will be used to control the progress of the interpolation between startValue and endValue:

  1.                 QPropertyAnimation animation;
  2. animation.setStartValue(0);
  3. animation.setEndValue(1000);
  4. animation.setDuration(1000);
  5. animation.setEasingCurve(QEasingCurve::InOutQuad);

The ability to set an amplitude, overshoot, or period depends on the QEasingCurve type. Amplitude access is available to curves that behave as springs such as elastic and bounce curves. Changing the amplitude changes the height of the curve. Period access is only available to elastic curves and setting a higher period slows the rate of bounce. Only curves that have "boomerang" behaviors such as the InBack, OutBack, InOutBack, and OutInBack have overshoot settings. These curves will interpolate beyond the end points and return to the end point, acting similar to a boomerang.

The Easing Curves Example contains samples of QEasingCurve types and lets you change the curve settings.

Public Types

Toggle detailsenum QEasingCurve::

TypeType { Linear , InQuad , OutQuad , InOutQuad , OutInQuad , InCubic , OutCubic , InOutCubic , OutInCubic , InQuart , OutQuart , InOutQuart , OutInQuart , InQuint , OutQuint , InOutQuint , OutInQuint , InSine , OutSine , InOutSine , OutInSine , InExpo , OutExpo , InOutExpo , OutInExpo , InCirc , OutCirc , InOutCirc , OutInCirc , InElastic , OutElastic , InOutElastic , OutInElastic , InBack , OutBack , InOutBack , OutInBack , InBounce , OutBounce , InOutBounce , OutInBounce , InCurve , OutCurve , SineCurve , CosineCurve , Custom , NCurveTypes 46 ...} { Linear , InQuad , OutQuad , InOutQuad , OutInQuad , InCubic , OutCubic , InOutCubic , OutInCubic , InQuart , OutQuart , InOutQuart , OutInQuart , InQuint , OutQuint , InOutQuint , OutInQuint , InSine , OutSine , InOutSine , OutInSine , InExpo , OutExpo , InOutExpo , OutInExpo , InCirc , OutCirc , InOutCirc , OutInCirc , InElastic , OutElastic , InOutElastic , OutInElastic , InBack , OutBack , InOutBack , OutInBack , InBounce , OutBounce , InOutBounce , OutInBounce , InCurve , OutCurve , SineCurve , CosineCurve , Custom , NCurveTypes 46 }

The type of easing curve.

ConstantValueDescription
QEasingCurve::Linear 0
Easing curve for a linear (t) function: velocity is constant.
QEasingCurve::InQuad 1
Easing curve for a quadratic (t^2) function: accelerating from zero velocity.
QEasingCurve::OutQuad 2
Easing curve for a quadratic (t^2) function: decelerating to zero velocity.
QEasingCurve::InOutQuad 3
Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration.
QEasingCurve::OutInQuad 4
Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration.
QEasingCurve::InCubic 5
Easing curve for a cubic (t^3) function: accelerating from zero velocity.
QEasingCurve::OutCubic 6
Easing curve for a cubic (t^3) function: decelerating to zero velocity.
QEasingCurve::InOutCubic 7
Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration.
QEasingCurve::OutInCubic 8
Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration.
QEasingCurve::InQuart 9
Easing curve for a quartic (t^4) function: accelerating from zero velocity.
QEasingCurve::OutQuart 10
Easing curve for a quartic (t^4) function: decelerating to zero velocity.
QEasingCurve::InOutQuart 11
Easing curve for a quartic (t^4) function: acceleration until halfway, then deceleration.
QEasingCurve::OutInQuart 12
Easing curve for a quartic (t^4) function: deceleration until halfway, then acceleration.
QEasingCurve::InQuint 13
Easing curve for a quintic (t^5) easing in: accelerating from zero velocity.
QEasingCurve::OutQuint 14
Easing curve for a quintic (t^5) function: decelerating to zero velocity.
QEasingCurve::InOutQuint 15
Easing curve for a quintic (t^5) function: acceleration until halfway, then deceleration.
QEasingCurve::OutInQuint 16
Easing curve for a quintic (t^5) function: deceleration until halfway, then acceleration.
QEasingCurve::InSine 17
Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity.
QEasingCurve::OutSine 18
Easing curve for a sinusoidal (sin(t)) function: decelerating from zero velocity.
QEasingCurve::InOutSine 19
Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration.
QEasingCurve::OutInSine 20
Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration.
QEasingCurve::InExpo 21
Easing curve for an exponential (2^t) function: accelerating from zero velocity.
QEasingCurve::OutExpo 22
Easing curve for an exponential (2^t) function: decelerating from zero velocity.
QEasingCurve::InOutExpo 23
Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration.
QEasingCurve::OutInExpo 24
Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration.
QEasingCurve::InCirc 25
Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity.
QEasingCurve::OutCirc 26
Easing curve for a circular (sqrt(1-t^2)) function: decelerating from zero velocity.
QEasingCurve::InOutCirc 27
Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration.
QEasingCurve::OutInCirc 28
Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration.
QEasingCurve::InElastic 29
Easing curve for an elastic (exponentially decaying sine wave) function: accelerating from zero velocity. The peak amplitude can be set with the amplitude parameter, and the period of decay by the period parameter.
QEasingCurve::OutElastic 30
Easing curve for an elastic (exponentially decaying sine wave) function: decelerating from zero velocity. The peak amplitude can be set with the amplitude parameter, and the period of decay by the period parameter.
QEasingCurve::InOutElastic 31
Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration.
QEasingCurve::OutInElastic 32
Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration.
QEasingCurve::InBack 33
Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity.
QEasingCurve::OutBack 34
Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity.
QEasingCurve::InOutBack 35
Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration.
QEasingCurve::OutInBack 36
Easing curve for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration.
QEasingCurve::InBounce 37
Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity.
QEasingCurve::OutBounce 38
Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating from zero velocity.
QEasingCurve::InOutBounce 39
Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration.
QEasingCurve::OutInBounce 40
Easing curve for a bounce (exponentially decaying parabolic bounce) function easing out/in: deceleration until halfway, then acceleration.
QEasingCurve::Custom 45 This is returned if the user specified a custom curve type with setCustomType(). Note that you cannot call setType() with this value, but type() can return it.

Look up this member in the source code.

    Types

    Toggle detailstypedef QEasingCurve EasingFunctionEasingFunction

    This is a typedef for a pointer to a function with the following signature:

    1.                     qreal myEasingFunction(qreal progress);

    Look up this member in the source code.

      Public Functions

      Toggle details QEasingCurve

      QEasingCurveQEasingCurve ( Type type=Linear ) ( Type type=Linear )

      Constructs an easing curve of the given type.

      Look up this member in the source code.

      Toggle details QEasingCurve

      QEasingCurveQEasingCurve ( const QEasingCurve &other ) ( const QEasingCurve &other )

      Construct a copy of other.

      Look up this member in the source code.

      Toggle details QEasingCurve

      ~QEasingCurve~QEasingCurve () ()

      Destructor.

      Look up this member in the source code.

      Toggle details qreal QEasingCurve

      amplitudeamplitude () ()const

      Returns the amplitude. This is not applicable for all curve types. It is only applicable for bounce and elastic curves (curves of type() QEasingCurve::InBounce, QEasingCurve::OutBounce, QEasingCurve::InOutBounce, QEasingCurve::OutInBounce, QEasingCurve::InElastic, QEasingCurve::OutElastic, QEasingCurve::InOutElastic or QEasingCurve::OutInElastic).

      See also setAmplitude().

      Look up this member in the source code.

      Toggle details EasingFunction QEasingCurve

      customTypecustomType () ()const

      Returns the function pointer to the custom easing curve. If type() does not return QEasingCurve::Custom, this function will return 0.

      See also setCustomType().

      Look up this member in the source code.

      Toggle details qreal QEasingCurve

      overshootovershoot () ()const

      Returns the overshoot. This is not applicable for all curve types. It is only applicable if type() is QEasingCurve::InBack, QEasingCurve::OutBack, QEasingCurve::InOutBack or QEasingCurve::OutInBack.

      See also setOvershoot().

      Look up this member in the source code.

      Toggle details qreal QEasingCurve

      periodperiod () ()const

      Returns the period. This is not applicable for all curve types. It is only applicable if type() is QEasingCurve::InElastic, QEasingCurve::OutElastic, QEasingCurve::InOutElastic or QEasingCurve::OutInElastic.

      See also setPeriod().

      Look up this member in the source code.

      Toggle details void QEasingCurve

      setAmplitudesetAmplitude ( qreal amplitude ) ( qreal amplitude )

      Sets the amplitude to amplitude.

      This will set the amplitude of the bounce or the amplitude of the elastic "spring" effect. The higher the number, the higher the amplitude.

      See also amplitude().

      Look up this member in the source code.

      Toggle details void QEasingCurve

      setCustomTypesetCustomType ( EasingFunction func ) ( EasingFunction func )

      Sets a custom easing curve that is defined by the user in the function func. The signature of the function is qreal myEasingFunction(qreal progress), where progress and the return value is considered to be normalized between 0 and 1. (In some cases the return value can be outside that range) After calling this function type() will return QEasingCurve::Custom. func cannot be zero.

      See also customType() and valueForProgress().

      Look up this member in the source code.

      Toggle details void QEasingCurve

      setOvershootsetOvershoot ( qreal overshoot ) ( qreal overshoot )

      Sets the overshoot to overshoot.

      0 produces no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent.

      See also overshoot().

      Look up this member in the source code.

      Toggle details void QEasingCurve

      setPeriodsetPeriod ( qreal period ) ( qreal period )

      Sets the period to period. Setting a small period value will give a high frequency of the curve. A large period will give it a small frequency.

      See also period().

      Look up this member in the source code.

      Toggle details void QEasingCurve

      setTypesetType ( Type type ) ( Type type )

      Sets the type of the easing curve to type.

      See also type().

      Look up this member in the source code.

      Toggle details Type QEasingCurve

      typetype () ()const

      Returns the type of the easing curve.

      See also setType().

      Look up this member in the source code.

      Toggle details qreal QEasingCurve

      valueForProgressvalueForProgress ( qreal progress ) ( qreal progress )const

      Return the effective progress for the easing curve at progress. While progress must be between 0 and 1, the returned effective progress can be outside those bounds. For instance, QEasingCurve::InBack will return negative values in the beginning of the function.

      Look up this member in the source code.

      Toggle details bool QEasingCurve

      operator!=operator!= ( const QEasingCurve &other ) ( const QEasingCurve &other )const

      Compare this easing curve with other and returns true if they are not equal. It will also compare the properties of a curve.

      See also operator==().

      Look up this member in the source code.

      Toggle details QEasingCurve & QEasingCurve

      operator=operator= ( const QEasingCurve &other ...) ( const QEasingCurve &other )

      Copy other.

      Look up this member in the source code.

      Toggle details bool QEasingCurve

      operator==operator== ( const QEasingCurve &other ) ( const QEasingCurve &other )const

      Compare this easing curve with other and returns true if they are equal. It will also compare the properties of a curve.

      Look up this member in the source code.

        Notes provided by the Qt Community

        No notes