Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-updates > by-pkgid > 6e2327ca1c896c6d674ae53117299f21 > files > 1719

qtdeclarative5-doc-5.12.6-1.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- animations.qdoc -->
  <title>Animation and Transitions in Qt Quick | Qt Quick 5.12.6</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qtquick-index.html">Qt Quick</a></td><td >Animation and Transitions in Qt Quick</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtquick-index.html">Qt 5.12.6 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#animation-and-transitions-types">Animation and Transitions Types</a></li>
<li class="level1"><a href="#triggering-animations">Triggering Animations</a></li>
<li class="level2"><a href="#direct-property-animation">Direct Property Animation</a></li>
<li class="level2"><a href="#using-predefined-targets-and-properties">Using Predefined Targets and Properties</a></li>
<li class="level2"><a href="#transitions-during-state-changes">Transitions During State Changes</a></li>
<li class="level2"><a href="#default-animation-as-behaviors">Default Animation as Behaviors</a></li>
<li class="level1"><a href="#playing-animations-in-parallel-or-in-sequence">Playing Animations in Parallel or in Sequence</a></li>
<li class="level1"><a href="#controlling-animations">Controlling Animations</a></li>
<li class="level2"><a href="#animation-playback">Animation Playback</a></li>
<li class="level2"><a href="#easing">Easing</a></li>
<li class="level2"><a href="#other-animation-types">Other Animation Types</a></li>
<li class="level1"><a href="#sharing-animation-instances">Sharing Animation Instances</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Animation and Transitions in Qt Quick</h1>
<span class="subtitle"></span>
<!-- $$$qtquick-statesanimations-animations.html-description -->
<div class="descr"> <a name="details"></a>
<a name="animation-and-transitions-types"></a>
<h2 id="animation-and-transitions-types">Animation and Transitions Types</h2>
<ul>
<li><a href="qmlexampletoggleswitch.html#transition">Transition</a> - Animates transitions during state changes</li>
<li><a href="qml-qtquick-sequentialanimation.html">SequentialAnimation</a> - Runs animations sequentially</li>
<li><a href="qml-qtquick-parallelanimation.html">ParallelAnimation</a> - Runs animations in parallel</li>
<li><a href="qml-qtquick-behavior.html">Behavior</a> - Specifies a default animation for property changes</li>
<li><a href="qml-qtquick-propertyaction.html">PropertyAction</a> - Sets immediate property changes during animation</li>
<li><a href="qml-qtquick-pauseanimation.html">PauseAnimation</a> - Introduces a pause in an animation</li>
<li><a href="qml-qtquick-smoothedanimation.html">SmoothedAnimation</a> - Allows a property to smoothly track a value</li>
<li><a href="qml-qtquick-springanimation.html">SpringAnimation</a> - Allows a property to track a value in a spring-like motion</li>
<li><a href="qml-qtquick-scriptaction.html">ScriptAction</a> - Runs scripts during an animation</li>
</ul>
<p>Types that animate properties based on data types <div class="table"><table class="annotated">
<tr class="odd topAlign"><td class="tblName"><p><a href="qml-qtquick-anchoranimation.html">AnchorAnimation</a></p></td><td class="tblDescr"><p>Animates changes in anchor values</p></td></tr>
<tr class="even topAlign"><td class="tblName"><p><a href="qml-qtquick-coloranimation.html">ColorAnimation</a></p></td><td class="tblDescr"><p>Animates changes in color values</p></td></tr>
<tr class="odd topAlign"><td class="tblName"><p><a href="qml-qtquick-numberanimation.html">NumberAnimation</a></p></td><td class="tblDescr"><p>Animates changes in qreal-type values</p></td></tr>
<tr class="even topAlign"><td class="tblName"><p><a href="qml-qtquick-parentanimation.html">ParentAnimation</a></p></td><td class="tblDescr"><p>Animates changes in parent values</p></td></tr>
<tr class="odd topAlign"><td class="tblName"><p><a href="qml-qtquick-pathanimation.html">PathAnimation</a></p></td><td class="tblDescr"><p>Animates an item along a path</p></td></tr>
<tr class="even topAlign"><td class="tblName"><p><a href="qml-qtquick-propertyanimation.html">PropertyAnimation</a></p></td><td class="tblDescr"><p>Animates changes in property values</p></td></tr>
<tr class="odd topAlign"><td class="tblName"><p><a href="qml-qtquick-rotationanimation.html">RotationAnimation</a></p></td><td class="tblDescr"><p>Animates changes in rotation values</p></td></tr>
<tr class="even topAlign"><td class="tblName"><p><a href="qml-qtquick-vector3danimation.html">Vector3dAnimation</a></p></td><td class="tblDescr"><p>Animates changes in QVector3d values</p></td></tr>
</table></div>
</p>
<p>Animations are created by applying animation types to property values. Animation types will interpolate property values to create smooth transitions. As well, state transitions may assign animations to state changes.</p>
<p>To create an animation, use an appropriate animation type for the type of the property that is to be animated, and apply the animation depending on the type of behavior that is required.</p>
<a name="triggering-animations"></a>
<h2 id="triggering-animations">Triggering Animations</h2>
<p>There are several ways of setting animation to an object.</p>
<a name="direct-property-animation"></a>
<h3 id="direct-property-animation">Direct Property Animation</h3>
<p>Animations are created by applying animation objects to property values to gradually change the properties over time. These <i>property animations</i> apply smooth movements by interpolating values between property value changes. Property animations provide timing controls and allows different interpolations through <a href="qtquick-statesanimations-animations.html#qml-easing-animation">easing curves</a>.</p>
<pre class="qml">

  Rectangle {
      id: flashingblob
      width: 75; height: 75
      color: "blue"
      opacity: 1.0

      MouseArea {
          anchors.fill: parent
          onClicked: {
              animateColor.start()
              animateOpacity.start()
          }
      }

      PropertyAnimation {id: animateColor; target: flashingblob; properties: "color"; to: "green"; duration: 100}

      NumberAnimation {
          id: animateOpacity
          target: flashingblob
          properties: "opacity"
          from: 0.99
          to: 1.0
          loops: Animation.Infinite
          easing {type: Easing.OutBack; overshoot: 500}
     }
  }

</pre>
<p>Specialized property animation types have more efficient implementations than the <a href="qtquick-animation-example.html#propertyanimation">PropertyAnimation</a> type. They are for setting animations to different QML types such as <code>int</code>, <code>color</code>, and rotations. Similarly, the <a href="qml-qtquick-parentanimation.html">ParentAnimation</a> can animate parent changes.</p>
<p>See the <a href="qtquick-statesanimations-animations.html#qml-controlling-animations">Controlling Animations</a> section for more information about the different animation properties.</p>
<a name="using-predefined-targets-and-properties"></a>
<h3 id="using-predefined-targets-and-properties">Using Predefined Targets and Properties</h3>
<p>In the previous example, the <a href="qtquick-animation-example.html#propertyanimation">PropertyAnimation</a> and <a href="qml-qtquick-numberanimation.html">NumberAnimation</a> objects needed to specify particular <a href="qml-qtquick-propertyanimation.html#target-prop">target</a> and <a href="qml-qtquick-propertyanimation.html#properties-prop">properties</a> values to specify the objects and properties that should be animated. This can be avoided by using the <i>&lt;Animation&gt; on &lt;Property&gt;</i> syntax, which specifies the animation is to be applied as a <i>property value source</i>.</p>
<p>Below are two <a href="qtquick-animation-example.html#propertyanimation">PropertyAnimation</a> objects that are specified using this syntax:</p>
<pre class="qml">



</pre>
<p>The animation starts as soon as the rectangle is loaded, and will automatically be applied to its <code>x</code> and <code>y</code> values. Since the <i>&lt;Animation&gt; on &lt;Property&gt;</i> syntax has been used, it is not necessary to set the <a href="qml-qtquick-propertyanimation.html#target-prop">target</a> value of the <a href="qtquick-animation-example.html#propertyanimation">PropertyAnimation</a> objects to <code>rect</code>, and neither is it necessary to set the <a href="qml-qtquick-propertyanimation.html#property-prop">property</a> values to <code>x</code> and <code>y</code>.</p>
<p>This can also be used by <a href="qtquick-statesanimations-animations.html#playing-animations-in-parallel-or-in-sequence">grouped animations</a> to ensure that all animations within a group are applied to the same property. For example, the previous example could instead use <a href="qml-qtquick-sequentialanimation.html">SequentialAnimation</a> to animate the rectangle's <code>color</code> first to yellow, then to blue:</p>
<pre class="qml">



</pre>
<p>Since the <a href="qml-qtquick-sequentialanimation.html">SequentialAnimation</a> object has been specified on the <code>color</code> property using the <i>&lt;Animation&gt; on &lt;Property&gt;</i> syntax, its child <a href="qtquick-animation-example.html#coloranimation">ColorAnimation</a> objects are also automatically applied to this property and do not need to specify <a href="qml-qtquick-propertyanimation.html#target-prop">target</a> or <a href="qml-qtquick-propertyanimation.html#property-prop">property</a> animation values.</p>
<a name="qml-transition-animations"></a><a name="transitions-during-state-changes"></a>
<h3 id="transitions-during-state-changes">Transitions During State Changes</h3>
<p><a href="qml-qtquick-state.html">Qt Quick States</a> are property configurations where a property may have different values to reflect different states. State changes introduce abrupt property changes; animations smooth transitions to produce visually appealing state changes.</p>
<p>The <a href="qmlexampletoggleswitch.html#transition">Transition</a> type can contain animation types to interpolate property changes caused by state changes. To assign the transition to an object, bind it to the <code>transitions</code> property.</p>
<p>A button might have two states, the <code>pressed</code> state when the user clicks on the button and a <code>released</code> state when the user releases the button. We can assign different property configurations for each state. A transition would animate the change from the <code>pressed</code> state to the <code>released</code> state. Likewise, there would be an animation during the change from the <code>released</code> state to the <code>pressed</code> state.</p>
<pre class="qml">

  Rectangle {
      width: 75; height: 75
      id: button
      state: "RELEASED"

      MouseArea {
          anchors.fill: parent
          onPressed: button.state = "PRESSED"
          onReleased: button.state = "RELEASED"
      }

      states: [
          State {
              name: "PRESSED"
              PropertyChanges { target: button; color: "lightblue"}
          },
          State {
              name: "RELEASED"
              PropertyChanges { target: button; color: "lightsteelblue"}
          }
      ]

      transitions: [
          Transition {
              from: "PRESSED"
              to: "RELEASED"
              ColorAnimation { target: button; duration: 100}
          },
          Transition {
              from: "RELEASED"
              to: "PRESSED"
              ColorAnimation { target: button; duration: 100}
          }
      ]
  }

</pre>
<p>Binding the <code>to</code> and <code>from</code> properties to the state's name will assign that particular transition to the state change. For simple or symmetric transitions, setting the to <code>to</code> property to the wild card symbol, &quot;<code>*</code>&quot;, denotes that the transition applies to any state change.</p>
<pre class="qml">

      transitions:
          Transition {
              to: "*"
              ColorAnimation { target: button; duration: 100}
          }

</pre>
<a name="default-animation-as-behaviors"></a>
<h3 id="default-animation-as-behaviors">Default Animation as Behaviors</h3>
<p>Default property animations are set using <i>behavior animations</i>. Animations declared in <a href="qml-qtquick-behavior.html">Behavior</a> types apply to the property and animates any property value changes. However, Behavior types have an <code>enabled</code> property to purposely enable or disable the behavior animations.</p>
<p>A ball component might have a behavior animation assigned to its <code>x</code>, <code>y</code>, and <code>color</code> properties. The behavior animation could be set up to simulate an elastic effect. In effect, this behavior animation would apply the elastic effect to the properties whenever the ball moves.</p>
<pre class="qml">

  Rectangle {
      width: 75; height: 75; radius: width
      id: ball
      color: "salmon"

      Behavior on x {
          NumberAnimation {
              id: bouncebehavior
              easing {
                  type: Easing.OutElastic
                  amplitude: 1.0
                  period: 0.5
              }
          }
      }
      Behavior on y {
          animation: bouncebehavior
      }
      Behavior {
          ColorAnimation { target: ball; duration: 100 }
      }
  }

</pre>
<p>There are several methods of assigning behavior animations to properties. The <code>Behavior on &lt;property&gt;</code> declaration is a convenient way of assigning a behavior animation onto a property.</p>
<p>See the <a href="qtquick-animation-example.html">Qt Quick Examples - Animation</a> for a demonstration of behavioral animations.</p>
<a name="playing-animations-in-parallel-or-in-sequence"></a>
<h2 id="playing-animations-in-parallel-or-in-sequence">Playing Animations in Parallel or in Sequence</h2>
<p>Animations can run <i>in parallel</i> or <i>in sequence</i>. Parallel animations will play a group of animations at the same time while sequential animations play a group of animations in order: one after the other. Grouping animations in <a href="qml-qtquick-sequentialanimation.html">SequentialAnimation</a> and <a href="qml-qtquick-parallelanimation.html">ParallelAnimation</a> will play the animations in sequence or in parallel.</p>
<p>A banner component may have several icons or slogans to display, one after the other. The <code>opacity</code> property could transform to <code>1.0</code> denoting an opaque object. Using the <a href="qml-qtquick-sequentialanimation.html">SequentialAnimation</a> type, the opacity animations will play after the preceding animation finishes. The <a href="qml-qtquick-parallelanimation.html">ParallelAnimation</a> type will play the animations at the same time.</p>
<pre class="qml">

  Rectangle {
      id: banner
      width: 150; height: 100; border.color: "black"

      Column {
          anchors.centerIn: parent
          Text {
              id: code
              text: "Code less."
              opacity: 0.01
          }
          Text {
              id: create
              text: "Create more."
              opacity: 0.01
          }
          Text {
              id: deploy
              text: "Deploy everywhere."
              opacity: 0.01
          }
      }

      MouseArea {
          anchors.fill: parent
          onPressed: playbanner.start()
      }

      SequentialAnimation {
          id: playbanner
          running: false
          NumberAnimation { target: code; property: "opacity"; to: 1.0; duration: 200}
          NumberAnimation { target: create; property: "opacity"; to: 1.0; duration: 200}
          NumberAnimation { target: deploy; property: "opacity"; to: 1.0; duration: 200}
      }
  }

</pre>
<p>Once individual animations are placed into a <a href="qml-qtquick-sequentialanimation.html">SequentialAnimation</a> or <a href="qml-qtquick-parallelanimation.html">ParallelAnimation</a>, they can no longer be started and stopped independently. The sequential or parallel animation must be started and stopped as a group.</p>
<p>The <a href="qml-qtquick-sequentialanimation.html">SequentialAnimation</a> type is also useful for playing <a href="qtquick-statesanimations-animations.html#qml-transition-animations">transition animations</a> because animations are played in parallel inside transitions.</p>
<a name="qml-controlling-animations"></a><a name="controlling-animations"></a>
<h2 id="controlling-animations">Controlling Animations</h2>
<p>There are different methods to control animations.</p>
<a name="animation-playback"></a>
<h3 id="animation-playback">Animation Playback</h3>
<p>All animation types inherit from the <a href="qml-qtquick-animation.html">Animation</a> type. It is not possible to create <a href="qml-qtquick-animation.html">Animation</a> objects; instead, this type provides the essential properties and methods for animation types. Animation types have <code>start()</code>, <code>stop()</code>, <code>resume()</code>, <code>pause()</code>, <code>restart()</code>, and <code>complete()</code> -- all of these methods control the execution of animations.</p>
<a name="qml-easing-animation"></a><a name="easing"></a>
<h3 id="easing">Easing</h3>
<p>Easing curves define how the animation will interpolate between the start value and the end value. Different easing curves might go beyond the defined range of interpolation. The easing curves simplify the creation of animation effects such as bounce effects, acceleration, deceleration, and cyclical animations.</p>
<p>A QML object may have different easing curve for each property animation. There are also different parameters to control the curve, some of which are exclusive to a particular curve. For more information about the easing curves, visit the <a href="qml-qtquick-propertyanimation.html#easing.type-prop">easing</a> documentation.</p>
<p>The easing example visually demonstrates each of the different easing types.</p>
<a name="other-animation-types"></a>
<h3 id="other-animation-types">Other Animation Types</h3>
<p>In addition, QML provides several other types useful for animation:</p>
<ul>
<li><a href="qml-qtquick-pauseanimation.html">PauseAnimation</a>: enables pauses during animations</li>
<li><a href="qml-qtquick-scriptaction.html">ScriptAction</a>: allows JavaScript to be executed during an animation, and can be used together with <a href="qml-qtquick-statechangescript.html">StateChangeScript</a> to reused existing scripts</li>
<li><a href="qml-qtquick-propertyaction.html">PropertyAction</a>: changes a property <i>immediately</i> during an animation, without animating the property change</li>
</ul>
<p>These are specialized animation types that animate different property types</p>
<ul>
<li><a href="qml-qtquick-smoothedanimation.html">SmoothedAnimation</a>: a specialized <a href="qml-qtquick-numberanimation.html">NumberAnimation</a> that provides smooth changes in animation when the target value changes</li>
<li><a href="qml-qtquick-springanimation.html">SpringAnimation</a>: provides a spring-like animation with specialized attributes such as <a href="qml-qtquick-springanimation.html#mass-prop">mass</a>, <a href="qml-qtquick-springanimation.html#damping-prop">damping</a> and <a href="qml-qtquick-springanimation.html#epsilon-prop">epsilon</a></li>
<li><a href="qml-qtquick-parentanimation.html">ParentAnimation</a>: used for animating a parent change (see <a href="qml-qtquick-parentchange.html">ParentChange</a>)</li>
<li><a href="qml-qtquick-anchoranimation.html">AnchorAnimation</a>: used for animating an anchor change (see <a href="qml-qtquick-anchorchanges.html">AnchorChanges</a>)</li>
</ul>
<a name="sharing-animation-instances"></a>
<h2 id="sharing-animation-instances">Sharing Animation Instances</h2>
<p>Sharing animation instances between Transitions or Behaviors is not supported, and may lead to undefined behavior. In the following example, changes to the Rectangle's position will most likely not be correctly animated.</p>
<pre class="qml">



</pre>
<p>The easiest fix is to repeat the <a href="qml-qtquick-numberanimation.html">NumberAnimation</a> for both Behaviors. If the repeated animation is rather complex, you might also consider creating a custom animation component and assigning an instance to each Behavior, for example:</p>
<pre class="qml">



</pre>
<pre class="qml">



</pre>
</div>
<p><b>See also </b><a href="qtquick-animation-example.html">Qt Quick Examples - Animation</a>.</p>
<!-- @@@qtquick-statesanimations-animations.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>