QEasingCurve Class

The QEasingCurve class provides easing curves for controlling animation. More...

Header: #include <QEasingCurve>
qmake: QT += core
Since: Qt 4.6

This class was introduced in Qt 4.6.

Public Types

typedef EasingFunction
enum Type { Linear, InQuad, OutQuad, InOutQuad, OutInQuad, …, Custom }

Detailed Description

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,

     QEasingCurve easing(QEasingCurve::InOutQuad);

     for (qreal t = 0.0; t < 1.0; t += 0.1)
         qWarning() << "Effective progress" << t << "is"
                    << 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:

     QPropertyAnimation animation;
     animation.setStartValue(0);
     animation.setEndValue(1000);
     animation.setDuration(1000);
     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.

Member Type Documentation

typedef QEasingCurve::EasingFunction

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

 qreal myEasingFunction(qreal progress);

enum QEasingCurve::Type

The type of easing curve.

ConstantValue
QEasingCurve::Linear0

Easing curve for a linear (t) function: velocity is constant.

ConstantValue
QEasingCurve::InQuad1

Easing curve for a quadratic (t^2) function: accelerating from zero velocity.

ConstantValue
QEasingCurve::OutQuad2

Easing curve for a quadratic (t^2) function: decelerating to zero velocity.

ConstantValue
QEasingCurve::InOutQuad3

Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration.

ConstantValue
QEasingCurve::OutInQuad4

Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration.

ConstantValue
QEasingCurve::InCubic5

Easing curve for a cubic (t^3) function: accelerating from zero velocity.

ConstantValue
QEasingCurve::OutCubic6

Easing curve for a cubic (t^3) function: decelerating to zero velocity.

ConstantValue
QEasingCurve::InOutCubic7

Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration.

ConstantValue
QEasingCurve::OutInCubic8

Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration.

ConstantValue
QEasingCurve::InQuart9

Easing curve for a quartic (t^4) function: accelerating from zero velocity.

ConstantValue
QEasingCurve::OutQuart10

Easing curve for a quartic (t^4) function: decelerating to zero velocity.

ConstantValue
QEasingCurve::InOutQuart11

Easing curve for a quartic (t^4) function: acceleration until halfway, then deceleration.

ConstantValue
QEasingCurve::OutInQuart12

Easing curve for a quartic (t^4) function: deceleration until halfway, then acceleration.

ConstantValue
QEasingCurve::InQuint13

Easing curve for a quintic (t^5) easing in: accelerating from zero velocity.

ConstantValue
QEasingCurve::OutQuint14

Easing curve for a quintic (t^5) function: decelerating to zero velocity.

ConstantValue
QEasingCurve::InOutQuint15

Easing curve for a quintic (t^5) function: acceleration until halfway, then deceleration.

ConstantValue
QEasingCurve::OutInQuint16

Easing curve for a quintic (t^5) function: deceleration until halfway, then acceleration.

ConstantValue
QEasingCurve::InSine17

Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity.

ConstantValue
QEasingCurve::OutSine18

Easing curve for a sinusoidal (sin(t)) function: decelerating to zero velocity.

ConstantValue
QEasingCurve::InOutSine19

Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration.

ConstantValue
QEasingCurve::OutInSine20

Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration.

ConstantValue
QEasingCurve::InExpo21

Easing curve for an exponential (2^t) function: accelerating from zero velocity.

ConstantValue
QEasingCurve::OutExpo22

Easing curve for an exponential (2^t) function: decelerating to zero velocity.

ConstantValue
QEasingCurve::InOutExpo23

Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration.

ConstantValue
QEasingCurve::OutInExpo24

Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration.

ConstantValue
QEasingCurve::InCirc25

Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity.

ConstantValue
QEasingCurve::OutCirc26

Easing curve for a circular (sqrt(1-t^2)) function: decelerating to zero velocity.

ConstantValue
QEasingCurve::InOutCirc27

Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration.

ConstantValue
QEasingCurve::OutInCirc28

Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration.

ConstantValue
QEasingCurve::InElastic29

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.

ConstantValue
QEasingCurve::OutElastic30

Easing curve for an elastic (exponentially decaying sine wave) function: decelerating to zero velocity. The peak amplitude can be set with the amplitude parameter, and the period of decay by the period parameter.

ConstantValue
QEasingCurve::InOutElastic31

Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration.

ConstantValue
QEasingCurve::OutInElastic32

Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration.

ConstantValue
QEasingCurve::InBack33

Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity.

ConstantValue
QEasingCurve::OutBack34

Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity.

ConstantValue
QEasingCurve::InOutBack35

Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration.

ConstantValue
QEasingCurve::OutInBack36

Easing curve for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration.

ConstantValue
QEasingCurve::InBounce37

Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity.

ConstantValue
QEasingCurve::OutBounce38

Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating from zero velocity.

ConstantValue
QEasingCurve::InOutBounce39

Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration.

ConstantValue
QEasingCurve::OutInBounce40

Easing curve for a bounce (exponentially decaying parabolic bounce) function easing out/in: deceleration until halfway, then acceleration.

ConstantValueDescription
QEasingCurve::BezierSpline45Allows defining a custom easing curve using a cubic bezier spline
QEasingCurve::TCBSpline46Allows defining a custom easing curve using a TCB spline
QEasingCurve::Custom47This 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.

See also addCubicBezierSegment() and addTCBSegment().