1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qdeclarativetransition.cpp -->
<title>Qt 4.8: QML Transition Element</title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="content">
<a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
</div>
<div class="breadcrumb toolblock">
<ul>
<li class="first"><a href="index.html">Home</a></li>
<!-- Breadcrumbs go here -->
<li><a href="qdeclarativeelements.html">QML Elements</a></li>
<li>QML Transition Element</li>
</ul>
</div>
</div>
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#properties">Properties</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<h1 class="title">QML Transition Element</h1>
<span class="subtitle"></span>
<!-- $$$Transition-brief -->
<p>The Transition element defines animated transitions that occur on state changes. <a href="#details">More...</a></p>
<!-- @@@Transition -->
<p>This element was introduced in Qt 4.7.</p>
<ul>
<li><a href="qml-transition-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="properties"></a>
<h2>Properties</h2>
<ul>
<li class="fn"><b><b><a href="qml-transition.html#animations-prop">animations</a></b></b> : list<Animation></li>
<li class="fn"><b><b><a href="qml-transition.html#from-prop">from</a></b></b> : string</li>
<li class="fn"><b><b><a href="qml-transition.html#reversible-prop">reversible</a></b></b> : bool</li>
<li class="fn"><b><b><a href="qml-transition.html#to-prop">to</a></b></b> : string</li>
</ul>
<!-- $$$Transition-description -->
<a name="details"></a>
<h2>Detailed Description</h2>
<p>A Transition defines the animations to be applied when a <a href="qml-state.html">State</a> change occurs.</p>
<p>For example, the following <a href="qml-rectangle.html">Rectangle</a> has two states: the default state, and an added "moved" state. In the "moved state, the rectangle's position changes to (50, 50). The added Transition specifies that when the rectangle changes between the default and the "moved" state, any changes to the <tt>x</tt> and <tt>y</tt> properties should be animated, using an <tt>Easing.InOutQuad</tt>.</p>
<pre class="qml"> import QtQuick 1.0
<span class="type"><a href="qml-rectangle.html">Rectangle</a></span> {
<span class="name">id</span>: <span class="name">rect</span>
<span class="name">width</span>: <span class="number">100</span>; <span class="name">height</span>: <span class="number">100</span>
<span class="name">color</span>: <span class="string">"red"</span>
<span class="type"><a href="qml-mousearea.html">MouseArea</a></span> {
<span class="name">id</span>: <span class="name">mouseArea</span>
<span class="name">anchors</span>.fill: <span class="name">parent</span>
}
<span class="name">states</span>: <span class="name">State</span> {
<span class="name">name</span>: <span class="string">"moved"</span>; <span class="name">when</span>: <span class="name">mouseArea</span>.<span class="name">pressed</span>
<span class="type"><a href="qml-propertychanges.html">PropertyChanges</a></span> { <span class="name">target</span>: <span class="name">rect</span>; <span class="name">x</span>: <span class="number">50</span>; <span class="name">y</span>: <span class="number">50</span> }
}
<span class="name">transitions</span>: <span class="name">Transition</span> {
<span class="type"><a href="qml-numberanimation.html">NumberAnimation</a></span> { <span class="name">properties</span>: <span class="string">"x,y"</span>; <span class="name">easing</span>.type: <span class="name">Easing</span>.<span class="name">InOutQuad</span> }
}
}</pre>
<p>Notice the example does not require <a href="qml-propertyanimation.html#to-prop">to</a> and <a href="qml-propertyanimation.html#from-prop">from</a> values for the <a href="qml-numberanimation.html">NumberAnimation</a>. As a convenience, these properties are automatically set to the values of <tt>x</tt> and <tt>y</tt> before and after the state change; the <tt>from</tt> values are provided by the current values of <tt>x</tt> and <tt>y</tt>, and the <tt>to</tt> values are provided by the <a href="qml-propertychanges.html">PropertyChanges</a> object. If you wish, you can provide <a href="qml-propertyanimation.html#to-prop">to</a> and <a href="qml-propertyanimation.html#from-prop">from</a> values anyway to override the default values.</p>
<p>By default, a Transition's animations are applied for any state change in the parent item. The Transition <a href="qml-transition.html#from-prop">from</a> and <a href="qml-transition.html#to-prop">to</a> values can be set to restrict the animations to only be applied when changing from one particular state to another.</p>
<p>To define multiple transitions, specify <a href="qml-item.html#transitions-prop">Item::transitions</a> as a list:</p>
<pre class="qml"> <span class="name">transitions</span>: [
<span class="type">Transition</span> {
<span class="name">from</span>: <span class="string">"stop"</span>; <span class="name">to</span>: <span class="string">"go"</span>
<span class="type"><a href="qml-propertyanimation.html">PropertyAnimation</a></span> { <span class="name">target</span>: <span class="name">stopLight</span>
<span class="name">properties</span>: <span class="string">"color"</span>; <span class="name">duration</span>: <span class="number">1000</span> }
},
<span class="type">Transition</span> {
<span class="name">from</span>: <span class="string">"go"</span>; <span class="name">to</span>: <span class="string">"stop"</span>
<span class="type"><a href="qml-propertyanimation.html">PropertyAnimation</a></span> { <span class="name">target</span>: <span class="name">goLight</span>
<span class="name">properties</span>: <span class="string">"color"</span>; <span class="name">duration</span>: <span class="number">1000</span> }
} ]</pre>
<p>If multiple Transitions are specified, only a single (best-matching) Transition will be applied for any particular state change. In the example above, when changing to <tt>state1</tt>, the first transition will be used, rather than the more generic second transition.</p>
<p>If a state change has a Transition that matches the same property as a <a href="qml-behavior.html">Behavior</a>, the Transition animation overrides the <a href="qml-behavior.html">Behavior</a> for that state change.</p>
<p><b>See also </b><a href="qdeclarativeanimation.html">QML Animation and Transitions</a>, <a href="declarative-animation-states.html">states example</a>, <a href="qdeclarativestates.html#qmlstates">States</a>, and <a href="qtdeclarative.html">QtDeclarative</a>.</p>
<!-- @@@Transition -->
<h2>Property Documentation</h2>
<!-- $$$animations -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlPropNode"><p><a name="animations-prop"></a><span class="qmlreadonly">read-only</span><span class="qmldefault">default</span><span class="name">animations</span> : <span class="type"><a href="qml-list.html">list</a></span><<span class="type"><a href="qml-animation.html">Animation</a></span>></p></td></tr></table></div><div class="qmldoc"><p>This property holds a list of the animations to be run for this transition.</p>
<pre class="qml"></pre>
<p>The top-level animations are run in parallel. To run them sequentially, define them within a <a href="qml-sequentialanimation.html">SequentialAnimation</a>:</p>
<pre class="qml"> <span class="name">transitions</span>: <span class="name">Transition</span> {
<span class="type"><a href="qml-sequentialanimation.html">SequentialAnimation</a></span> {
<span class="type"><a href="qml-propertyanimation.html">PropertyAnimation</a></span> { <span class="name">property</span>: <span class="string">"x"</span>; <span class="name">duration</span>: <span class="number">1000</span> }
<span class="type"><a href="qml-coloranimation.html">ColorAnimation</a></span> { <span class="name">duration</span>: <span class="number">1000</span> }
}
}</pre>
</div></div><!-- @@@animations -->
<br/>
<!-- $$$from -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlPropNode"><p><a name="from-prop"></a><span class="name">from</span> : <span class="type"><a href="qml-string.html">string</a></span></p></td></tr><tr valign="top" class="even"><td class="tblQmlPropNode"><p><a name="to-prop"></a><span class="name">to</span> : <span class="type"><a href="qml-string.html">string</a></span></p></td></tr></table></div><div class="qmldoc"><p>These properties indicate the state changes that trigger the transition.</p>
<p>The default values for these properties is "*" (that is, any state).</p>
<p>For example, the following transition has not set the <tt>to</tt> and <tt>from</tt> properties, so the animation is always applied when changing between the two states (i.e. when the mouse is pressed and released).</p>
<pre class="qml"> <span class="type"><a href="qml-rectangle.html">Rectangle</a></span> {
<span class="name">id</span>: <span class="name">rect</span>
<span class="name">width</span>: <span class="number">100</span>; <span class="name">height</span>: <span class="number">100</span>
<span class="name">color</span>: <span class="string">"red"</span>
<span class="type"><a href="qml-mousearea.html">MouseArea</a></span> { <span class="name">id</span>: <span class="name">mouseArea</span>; <span class="name">anchors</span>.fill: <span class="name">parent</span> }
<span class="name">states</span>: <span class="name">State</span> {
<span class="name">name</span>: <span class="string">"brighter"</span>; <span class="name">when</span>: <span class="name">mouseArea</span>.<span class="name">pressed</span>
<span class="type"><a href="qml-propertychanges.html">PropertyChanges</a></span> { <span class="name">target</span>: <span class="name">rect</span>; <span class="name">color</span>: <span class="string">"yellow"</span> }
}
<span class="name">transitions</span>: <span class="name">Transition</span> {
<span class="type"><a href="qml-coloranimation.html">ColorAnimation</a></span> { <span class="name">duration</span>: <span class="number">1000</span> }
}
}</pre>
<p>If the transition was changed to this:</p>
<pre class="qml"> <span class="name">transitions</span>: <span class="name">Transition</span> {
<span class="name">to</span>: <span class="string">"brighter"</span>
<span class="type"><a href="qml-coloranimation.html">ColorAnimation</a></span> { <span class="name">duration</span>: <span class="number">1000</span> }
}</pre>
<p>The animation would only be applied when changing from the default state to the "brighter" state (i.e. when the mouse is pressed, but not on release).</p>
<p><b>See also </b><a href="qml-transition.html#reversible-prop">reversible</a>.</p>
</div></div><!-- @@@from -->
<br/>
<!-- $$$reversible -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlPropNode"><p><a name="reversible-prop"></a><span class="name">reversible</span> : <span class="type"><a href="qml-bool.html">bool</a></span></p></td></tr></table></div><div class="qmldoc"><p>This property holds whether the transition should be automatically reversed when the conditions that triggered this transition are reversed.</p>
<p>The default value is false.</p>
<p>By default, transitions run in parallel and are applied to all state changes if the <a href="qml-transition.html#from-prop">from</a> and <a href="qml-transition.html#to-prop">to</a> states have not been set. In this situation, the transition is automatically applied when a state change is reversed, and it is not necessary to set this property to reverse the transition.</p>
<p>However, if a <a href="qml-sequentialanimation.html">SequentialAnimation</a> is used, or if the <a href="qml-transition.html#from-prop">from</a> or <a href="qml-transition.html#to-prop">to</a> properties have been set, this property will need to be set to reverse a transition when a state change is reverted. For example, the following transition applies a sequential animation when the mouse is pressed, and reverses the sequence of the animation when the mouse is released:</p>
<pre class="qml"> <span class="type"><a href="qml-rectangle.html">Rectangle</a></span> {
<span class="name">id</span>: <span class="name">rect</span>
<span class="name">width</span>: <span class="number">100</span>; <span class="name">height</span>: <span class="number">100</span>
<span class="name">color</span>: <span class="string">"red"</span>
<span class="type"><a href="qml-mousearea.html">MouseArea</a></span> { <span class="name">id</span>: <span class="name">mouseArea</span>; <span class="name">anchors</span>.fill: <span class="name">parent</span> }
<span class="name">states</span>: <span class="name">State</span> {
<span class="name">name</span>: <span class="string">"brighter"</span>
<span class="name">when</span>: <span class="name">mouseArea</span>.<span class="name">pressed</span>
<span class="type"><a href="qml-propertychanges.html">PropertyChanges</a></span> { <span class="name">target</span>: <span class="name">rect</span>; <span class="name">color</span>: <span class="string">"yellow"</span>; <span class="name">x</span>: <span class="number">50</span> }
}
<span class="name">transitions</span>: <span class="name">Transition</span> {
<span class="type"><a href="qml-sequentialanimation.html">SequentialAnimation</a></span> {
<span class="type"><a href="qml-propertyanimation.html">PropertyAnimation</a></span> { <span class="name">property</span>: <span class="string">"x"</span>; <span class="name">duration</span>: <span class="number">1000</span> }
<span class="type"><a href="qml-coloranimation.html">ColorAnimation</a></span> { <span class="name">duration</span>: <span class="number">1000</span> }
}
}
}</pre>
<p>If the transition did not set the <tt>to</tt> and <tt>reversible</tt> values, then on the mouse release, the transition would play the <a href="qml-propertyanimation.html">PropertyAnimation</a> before the <a href="qml-coloranimation.html">ColorAnimation</a> instead of reversing the sequence.</p>
</div></div><!-- @@@reversible -->
<br/>
<div class="ft">
<span></span>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2012 Nokia Corporation and/or its
subsidiaries. Documentation contributions included herein are the copyrights of
their respective owners.</p>
<br />
<p>
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.</p>
<p>
Documentation sources may be obtained from <a href="http://www.qt-project.org">
www.qt-project.org</a>.</p>
<br />
<p>
Nokia, Qt and their respective logos are trademarks of Nokia Corporation
in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. <a title="Privacy Policy"
href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>
|