Sophie

Sophie

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

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" />
<!-- behaviors.qdoc -->
  <title>Using Qt Quick Behaviors with States | 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 >Using Qt Quick Behaviors with States</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="#using-behaviors-with-states">Using Behaviors with States</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Using Qt Quick Behaviors with States</h1>
<span class="subtitle"></span>
<!-- $$$qtquick-statesanimations-behaviors.html-description -->
<div class="descr"> <a name="details"></a>
<a name="using-behaviors-with-states"></a>
<h2 id="using-behaviors-with-states">Using Behaviors with States</h2>
<p>In some cases you may choose to use a Behavior to animate a property change caused by a state change. While this works well for some situations, in other situations it may lead to unexpected behavior.</p>
<p>Here's an example that shows the problem:</p>
<pre class="qml">



</pre>
<p>Testing the example by quickly and repeatedly moving the mouse in to and out of the colored rectangle shows that the colored rectangle will settle into a green color over time, never returning to full red. This is not what we wanted! The problem occurs because we have used a Behavior to animate the change in color, and our state change is trigged by the mouse entering or exiting the <a href="qml-qtquick-mousearea.html">MouseArea</a>, which is easily interrupted.</p>
<p>To state the problem more formally, using States and Behaviors together can cause unexpected behavior when:</p>
<ul>
<li>a Behavior is used to animate a property change, specifically when moving from an explicitly defined state back to the implicit base state; and</li>
<li>this Behavior can be interrupted to (re-)enter an explicitly defined state.</li>
</ul>
<p>The problem occurs because of the way the base state is defined for QML: as the &quot;snapshot&quot; state of the application just prior to entering an explicitly defined state. In this case, if we are in the process of animating from green back to red, and interrupt the animation to return to &quot;GreenState&quot;, the base state will include the color in its intermediate, mid-animation form.</p>
<p>While future versions of QML should be able to handle this situation more gracefully, there are currently several ways to rework your application to avoid this problem.</p>
<p>1. Use a transition to animate the change, rather than a Behavior.</p>
<pre class="qml">



</pre>
<p>2. Use a conditional binding to change the property value, rather than a state</p>
<pre class="qml">



</pre>
<p>3. Use only explicitly defined states, rather than an implicit base state</p>
<pre class="qml">



</pre>
</div>
<!-- @@@qtquick-statesanimations-behaviors.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>