qml-qt-labs-handlers-pinchhandler.html 20.3 KB
Newer Older
xuebingbing's avatar
xuebingbing committed
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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qquickpinchhandler.cpp -->
  <title>PinchHandler QML Type | Qt Quick 5.11</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 ><a href="../qtdoc/index.html">Qt 5.11</a></td><td ><a href="qtquick-index.html">Qt Quick</a></td><td ><a href="qtquick-qmlmodule.html">QML Types</a></td><td >PinchHandler QML Type</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.11.2 Reference Documentation</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="#properties">Properties</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">PinchHandler QML Type</h1>
<span class="subtitle"></span>
<!-- $$$PinchHandler-brief -->
<p>Handler for pinch gestures. <a href="#details">More...</a></p>
<!-- @@@PinchHandler -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Import Statement:</td><td class="memItemRight bottomAlign"> import Qt.labs.handlers 1.0</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <p><a href="qml-qt-labs-handlers-multipointhandler.html">MultiPointHandler</a></p>
</td></tr></table></div><ul>
<li><a href="qml-qt-labs-handlers-pinchhandler-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="properties"></a>
<h2 id="properties">Properties</h2>
<ul>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#active-prop">active</a></b></b> : bool</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#centroid-prop">centroid</a></b></b> : QPointF</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#centroidVelocity-prop">centroidVelocity</a></b></b> : QVector2D</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#maximumRotation-prop">maximumRotation</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#maximumScale-prop">maximumScale</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#maximumX-prop">maximumX</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#maximumY-prop">maximumY</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#minimumRotation-prop">minimumRotation</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#minimumScale-prop">minimumScale</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#minimumTouchPoints-prop">minimumTouchPoints</a></b></b> : int</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#minimumX-prop">minimumX</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#minimumY-prop">minimumY</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#pinchOrigin-prop">pinchOrigin</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#rotation-prop">rotation</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#scale-prop">scale</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qt-labs-handlers-pinchhandler.html#translation-prop">translation</a></b></b> : QVector2D</li>
</ul>
<!-- $$$PinchHandler-description -->
<a name="details"></a>
<h2 id="details">Detailed Description</h2>
<p><a href="qml-qt-labs-handlers-pinchhandler.html">PinchHandler</a> is a handler that interprets a multi-finger gesture to interactively rotate, zoom, and drag an Item. Like other Pointer Handlers, by default it is fully functional, and manipulates its <a href="../qmake/qmake-variable-reference.html#target">target</a>, which is the Item within which it is declared.</p>
<pre class="qml">

  import QtQuick 2.8
  import Qt.labs.handlers 1.0

  <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
      <span class="name">width</span>: <span class="number">400</span>
      <span class="name">height</span>: <span class="number">300</span>
      <span class="name">color</span>: <span class="string">&quot;lightsteelblue&quot;</span>
      <span class="type"><a href="qml-qt-labs-handlers-pinchhandler.html">PinchHandler</a></span> { }
  }

</pre>
<p>It has properties to restrict the range of dragging, rotation, and zoom.</p>
<p>If it is declared within one Item but is assigned a different <a href="../qmake/qmake-variable-reference.html#target">target</a>, it handles events within the bounds of the outer Item but manipulates the <code>target</code> Item instead:</p>
<pre class="qml">

  import QtQuick 2.8
  import Qt.labs.handlers 1.0

  <span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
      <span class="name">width</span>: <span class="number">640</span>
      <span class="name">height</span>: <span class="number">480</span>

      <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
          <span class="name">id</span>: <span class="name">map</span>
          <span class="name">color</span>: <span class="string">&quot;aqua&quot;</span>
          <span class="name">width</span>: <span class="number">400</span>
          <span class="name">height</span>: <span class="number">300</span>
      }

      <span class="type"><a href="qml-qt-labs-handlers-pinchhandler.html">PinchHandler</a></span> {
          <span class="name">target</span>: <span class="name">map</span>
      }
  }

</pre>
<p>A third way to use it is to set <a href="../qmake/qmake-variable-reference.html#target">target</a> to <code>null</code> and react to property changes in some other way:</p>
<pre class="qml">

  import QtQuick 2.8
  import Qt.labs.handlers 1.0

  <span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
      <span class="name">width</span>: <span class="number">640</span>
      <span class="name">height</span>: <span class="number">480</span>

      <span class="type"><a href="qml-qt-labs-handlers-pinchhandler.html">PinchHandler</a></span> {
          <span class="name">id</span>: <span class="name">handler</span>
          <span class="name">target</span>: <span class="number">null</span>
      }

      <span class="type"><a href="qml-qtquick-text.html">Text</a></span> {
          <span class="name">color</span>: <span class="name">handler</span>.<span class="name">active</span> ? <span class="string">&quot;darkgreen&quot;</span> : <span class="string">&quot;black&quot;</span>
          <span class="name">text</span>: <span class="name">handler</span>.<span class="name">rotation</span>.<span class="name">toFixed</span>(<span class="number">1</span>) <span class="operator">+</span> <span class="string">&quot; degrees\n&quot;</span> <span class="operator">+</span>
                <span class="name">handler</span>.<span class="name">translation</span>.<span class="name">x</span>.<span class="name">toFixed</span>(<span class="number">1</span>) <span class="operator">+</span> <span class="string">&quot;, &quot;</span> <span class="operator">+</span> <span class="name">handler</span>.<span class="name">translation</span>.<span class="name">y</span>.<span class="name">toFixed</span>(<span class="number">1</span>) <span class="operator">+</span> <span class="string">&quot;\n&quot;</span> <span class="operator">+</span>
                (<span class="name">handler</span>.<span class="name">scale</span> <span class="operator">*</span> <span class="number">100</span>).<span class="name">toFixed</span>(<span class="number">1</span>) <span class="operator">+</span> <span class="string">&quot;%&quot;</span>
      }
  }

</pre>
<p class="centerAlign"><img src="images/touchpoints-pinchhandler.png" alt="" /></p><p><b>See also </b><a href="qml-qtquick-pincharea.html">PinchArea</a>.</p>
<!-- @@@PinchHandler -->
<h2>Property Documentation</h2>
<!-- $$$active -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="active-prop">
<td class="tblQmlPropNode"><p>
<a name="active-prop"></a><span class="name">active</span> : <span class="type"><a href="../qtqml/qml-bool.html">bool</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>This property is true when all the constraints (epecially <a href="qml-qt-labs-handlers-pinchhandler.html#minimumTouchPoints-prop">minimumTouchPoints</a>) are satisfied and the <a href="../qmake/qmake-variable-reference.html#target">target</a>, if any, is being manipulated.</p>
</div></div><!-- @@@active -->
<br/>
<!-- $$$centroid -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="centroid-prop">
<td class="tblQmlPropNode"><p>
<a name="centroid-prop"></a><span class="qmlreadonly">[read-only] </span><span class="name">centroid</span> : <span class="type">QPointF</span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>A point exactly in the middle of the currently-pressed touch points. If <a href="qml-qt-labs-handlers-pinchhandler.html#pinchOrigin-prop">pinchOrigin</a> is set to <code>PinchCenter</code>, the <a href="../qmake/qmake-variable-reference.html#target">target</a> will be rotated around this point.</p>
</div></div><!-- @@@centroid -->
<br/>
<!-- $$$centroidVelocity -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="centroidVelocity-prop">
<td class="tblQmlPropNode"><p>
<a name="centroidVelocity-prop"></a><span class="qmlreadonly">[read-only] </span><span class="name">centroidVelocity</span> : <span class="type">QVector2D</span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The average velocity of the <a href="qml-qt-labs-handlers-pinchhandler.html#centroid-prop">centroid</a>: a vector representing the speed and direction of movement of the whole group of touchpoints, in logical pixels per second.</p>
</div></div><!-- @@@centroidVelocity -->
<br/>
<!-- $$$maximumRotation -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="maximumRotation-prop">
<td class="tblQmlPropNode"><p>
<a name="maximumRotation-prop"></a><span class="name">maximumRotation</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The maximum acceptable <a href="qml-qtquick-item.html#rotation-prop">rotation</a> to be applied to the <a href="../qmake/qmake-variable-reference.html#target">target</a>.</p>
</div></div><!-- @@@maximumRotation -->
<br/>
<!-- $$$maximumScale -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="maximumScale-prop">
<td class="tblQmlPropNode"><p>
<a name="maximumScale-prop"></a><span class="name">maximumScale</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The maximum acceptable <a href="qml-qtquick-item.html#scale-prop">scale</a> to be applied to the <a href="../qmake/qmake-variable-reference.html#target">target</a>.</p>
</div></div><!-- @@@maximumScale -->
<br/>
<!-- $$$maximumX -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="maximumX-prop">
<td class="tblQmlPropNode"><p>
<a name="maximumX-prop"></a><span class="name">maximumX</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The maximum acceptable x coordinate of the centroid</p>
</div></div><!-- @@@maximumX -->
<br/>
<!-- $$$maximumY -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="maximumY-prop">
<td class="tblQmlPropNode"><p>
<a name="maximumY-prop"></a><span class="name">maximumY</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The maximum acceptable y coordinate of the centroid</p>
</div></div><!-- @@@maximumY -->
<br/>
<!-- $$$minimumRotation -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="minimumRotation-prop">
<td class="tblQmlPropNode"><p>
<a name="minimumRotation-prop"></a><span class="name">minimumRotation</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The minimum acceptable <a href="qml-qtquick-item.html#rotation-prop">rotation</a> to be applied to the <a href="../qmake/qmake-variable-reference.html#target">target</a>.</p>
</div></div><!-- @@@minimumRotation -->
<br/>
<!-- $$$minimumScale -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="minimumScale-prop">
<td class="tblQmlPropNode"><p>
<a name="minimumScale-prop"></a><span class="name">minimumScale</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The minimum acceptable <a href="qml-qtquick-item.html#scale-prop">scale</a> to be applied to the <a href="../qmake/qmake-variable-reference.html#target">target</a>.</p>
</div></div><!-- @@@minimumScale -->
<br/>
<!-- $$$minimumTouchPoints -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="minimumTouchPoints-prop">
<td class="tblQmlPropNode"><p>
<a name="minimumTouchPoints-prop"></a><span class="name">minimumTouchPoints</span> : <span class="type"><a href="../qtqml/qml-int.html">int</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The pinch begins when this number of fingers are pressed. Until then, <a href="qml-qt-labs-handlers-pinchhandler.html">PinchHandler</a> tracks the positions of any pressed fingers, but if it's an insufficient number, it does not scale or rotate its <a href="../qmake/qmake-variable-reference.html#target">target</a>, and the <a href="qml-qt-labs-handlers-pinchhandler.html#active-prop">active</a> property will remain false.</p>
</div></div><!-- @@@minimumTouchPoints -->
<br/>
<!-- $$$minimumX -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="minimumX-prop">
<td class="tblQmlPropNode"><p>
<a name="minimumX-prop"></a><span class="name">minimumX</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The minimum acceptable x coordinate of the centroid</p>
</div></div><!-- @@@minimumX -->
<br/>
<!-- $$$minimumY -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="minimumY-prop">
<td class="tblQmlPropNode"><p>
<a name="minimumY-prop"></a><span class="name">minimumY</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The minimum acceptable y coordinate of the centroid</p>
</div></div><!-- @@@minimumY -->
<br/>
<!-- $$$pinchOrigin -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="pinchOrigin-prop">
<td class="tblQmlPropNode"><p>
<a name="pinchOrigin-prop"></a><span class="name">pinchOrigin</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The point to be held in place, around which the <a href="../qmake/qmake-variable-reference.html#target">target</a> is scaled and rotated.</p>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><code>FirstPoint</code></td><td class="topAlign">the first touch point, wherever the first finger is pressed</td></tr>
<tr><td class="topAlign"><code>PinchCenter</code></td><td class="topAlign">the centroid between all the touch points at the time when the <a href="qml-qt-labs-handlers-pinchhandler.html">PinchHandler</a> becomes <a href="qml-qt-labs-handlers-pinchhandler.html#active-prop">active</a></td></tr>
<tr><td class="topAlign"><code>TargetCenter</code></td><td class="topAlign">the center of the <a href="../qmake/qmake-variable-reference.html#target">target</a></td></tr>
</table></div>
</div></div><!-- @@@pinchOrigin -->
<br/>
<!-- $$$rotation -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="rotation-prop">
<td class="tblQmlPropNode"><p>
<a name="rotation-prop"></a><span class="qmlreadonly">[read-only] </span><span class="name">rotation</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The rotation of the pinch gesture in degrees, with positive values clockwise. It is 0 when the gesture begins. If <a href="../qmake/qmake-variable-reference.html#target">target</a> is not null, this will be automatically applied to its <a href="qml-qtquick-item.html#rotation-prop">rotation</a>. Otherwise, bindings can be used to do arbitrary things with this value.</p>
</div></div><!-- @@@rotation -->
<br/>
<!-- $$$scale -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="scale-prop">
<td class="tblQmlPropNode"><p>
<a name="scale-prop"></a><span class="qmlreadonly">[read-only] </span><span class="name">scale</span> : <span class="type"><a href="../qtqml/qml-real.html">real</a></span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The scale factor. It is 1.0 when the gesture begins, increases as the touchpoints are spread apart, and decreases as the touchpoints are brought together. If <a href="../qmake/qmake-variable-reference.html#target">target</a> is not null, this will be automatically applied to its <a href="qml-qtquick-item.html#scale-prop">scale</a>. Otherwise, bindings can be used to do arbitrary things with this value.</p>
</div></div><!-- @@@scale -->
<br/>
<!-- $$$translation -->
<div class="qmlitem"><div class="qmlproto">
<div class="table"><table class="qmlname">
<tr valign="top" class="odd" id="translation-prop">
<td class="tblQmlPropNode"><p>
<a name="translation-prop"></a><span class="qmlreadonly">[read-only] </span><span class="name">translation</span> : <span class="type">QVector2D</span></p></td></tr>
</table></div>
</div><div class="qmldoc"><p>The translation of the gesture <a href="qml-qt-labs-handlers-pinchhandler.html#centroid-prop">centroid</a>. It is <code>(0, 0)</code> when the gesture begins.</p>
</div></div><!-- @@@translation -->
<br/>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2018 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>