<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qquickstateoperations.cpp --> <title>AnchorChanges QML Type | Qt Quick 5.9</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.9</td><td ><a href="qtquick-index.html">Qt Quick</a></td><td ><a href="qtquick-qmlmodule.html">QML Types</a></td><td >AnchorChanges QML Type</td></tr></table><table class="buildversion"><tr> <td id="buildversion" width="100%" align="right">Qt 5.9.4 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">AnchorChanges QML Type</h1> <span class="subtitle"></span> <!-- $$$AnchorChanges-brief --> <p>Specifies how to change the anchors of an item in a state <a href="#details">More...</a></p> <!-- @@@AnchorChanges --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Import Statement:</td><td class="memItemRight bottomAlign"> import QtQuick 2.7</td></tr></table></div><ul> <li><a href="qml-qtquick-anchorchanges-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-qtquick-anchorchanges.html#anchors-prop">anchors</a></b></b><ul> <li class="fn"><b><b><a href="qml-qtquick-anchorchanges.html#anchors.left-prop">anchors.left</a></b></b> : AnchorLine</li> <li class="fn"><b><b><a href="qml-qtquick-anchorchanges.html#anchors.right-prop">anchors.right</a></b></b> : AnchorLine</li> <li class="fn"><b><b><a href="qml-qtquick-anchorchanges.html#anchors.horizontalCenter-prop">anchors.horizontalCenter</a></b></b> : AnchorLine</li> <li class="fn"><b><b><a href="qml-qtquick-anchorchanges.html#anchors.top-prop">anchors.top</a></b></b> : AnchorLine</li> <li class="fn"><b><b><a href="qml-qtquick-anchorchanges.html#anchors.bottom-prop">anchors.bottom</a></b></b> : AnchorLine</li> <li class="fn"><b><b><a href="qml-qtquick-anchorchanges.html#anchors.verticalCenter-prop">anchors.verticalCenter</a></b></b> : AnchorLine</li> <li class="fn"><b><b><a href="qml-qtquick-anchorchanges.html#anchors.baseline-prop">anchors.baseline</a></b></b> : AnchorLine</li> </ul> </li> <li class="fn"><b><b><a href="qml-qtquick-anchorchanges.html#target-prop">target</a></b></b> : Item</li> </ul> <!-- $$$AnchorChanges-description --> <a name="details"></a> <h2 id="details">Detailed Description</h2> <p>The <a href="qml-qtquick-anchorchanges.html">AnchorChanges</a> type is used to modify the anchors of an item in a <a href="qml-qtquick-state.html">State</a>.</p> <p><a href="qml-qtquick-anchorchanges.html">AnchorChanges</a> cannot be used to modify the margins on an item. For this, use <a href="qml-qtquick-propertychanges.html">PropertyChanges</a> intead.</p> <p>In the following example we change the top and bottom anchors of an item using <a href="qml-qtquick-anchorchanges.html">AnchorChanges</a>, and the top and bottom anchor margins using <a href="qml-qtquick-propertychanges.html">PropertyChanges</a>:</p> <pre class="qml"> import QtQuick 2.0 <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> { <span class="name">id</span>: <span class="name">window</span> <span class="name">width</span>: <span class="number">120</span>; <span class="name">height</span>: <span class="number">120</span> <span class="name">color</span>: <span class="string">"black"</span> <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> { <span class="name">id</span>: <span class="name">myRect</span>; <span class="name">width</span>: <span class="number">50</span>; <span class="name">height</span>: <span class="number">50</span>; <span class="name">color</span>: <span class="string">"red"</span> } <span class="name">states</span>: <span class="name">State</span> { <span class="name">name</span>: <span class="string">"reanchored"</span> <span class="type"><a href="qml-qtquick-anchorchanges.html">AnchorChanges</a></span> { <span class="name">target</span>: <span class="name">myRect</span> <span class="name">anchors</span>.top: <span class="name">window</span>.<span class="name">top</span> <span class="name">anchors</span>.bottom: <span class="name">window</span>.<span class="name">bottom</span> } <span class="type"><a href="qml-qtquick-propertychanges.html">PropertyChanges</a></span> { <span class="name">target</span>: <span class="name">myRect</span> <span class="name">anchors</span>.topMargin: <span class="number">10</span> <span class="name">anchors</span>.bottomMargin: <span class="number">10</span> } } <span class="type"><a href="qml-qtquick-mousearea.html">MouseArea</a></span> { <span class="name">anchors</span>.fill: <span class="name">parent</span>; <span class="name">onClicked</span>: <span class="name">window</span>.<span class="name">state</span> <span class="operator">=</span> <span class="string">"reanchored"</span> } } </pre> <p class="centerAlign"><img src="images/anchorchanges.png" alt="" /></p><p><a href="qml-qtquick-anchorchanges.html">AnchorChanges</a> can be animated using <a href="qml-qtquick-anchoranimation.html">AnchorAnimation</a>.</p> <pre class="qml"> <span class="comment">//animate our anchor changes</span> <span class="type"><a href="qml-qtquick-transition.html">Transition</a></span> { <span class="type"><a href="qml-qtquick-anchoranimation.html">AnchorAnimation</a></span> {} } </pre> <p>Changes to anchor margins can be animated using <a href="qml-qtquick-numberanimation.html">NumberAnimation</a>.</p> <p>For more information on anchors see <a href="qtquick-positioning-anchors.html">Anchor Layouts</a>.</p> <!-- @@@AnchorChanges --> <h2>Property Documentation</h2> <!-- $$$anchors --> <div class="qmlitem"><div class="qmlproto"><div class="table"><table class="qmlname"><tr valign="top" class="even" id="anchors-prop"><th class="centerAlign"><p><a name="anchors-prop"></a><b>anchors group</b></p></th></tr><tr valign="top" class="odd" id="anchors.left-prop"><td class="tblQmlPropNode"><p><a name="anchors.left-prop"></a><span class="name">anchors.left</span> : <span class="type">AnchorLine</span></p></td></tr><tr valign="top" class="odd" id="anchors.right-prop"><td class="tblQmlPropNode"><p><a name="anchors.right-prop"></a><span class="name">anchors.right</span> : <span class="type">AnchorLine</span></p></td></tr><tr valign="top" class="odd" id="anchors.horizontalCenter-prop"><td class="tblQmlPropNode"><p><a name="anchors.horizontalCenter-prop"></a><span class="name">anchors.horizontalCenter</span> : <span class="type">AnchorLine</span></p></td></tr><tr valign="top" class="odd" id="anchors.top-prop"><td class="tblQmlPropNode"><p><a name="anchors.top-prop"></a><span class="name">anchors.top</span> : <span class="type">AnchorLine</span></p></td></tr><tr valign="top" class="odd" id="anchors.bottom-prop"><td class="tblQmlPropNode"><p><a name="anchors.bottom-prop"></a><span class="name">anchors.bottom</span> : <span class="type">AnchorLine</span></p></td></tr><tr valign="top" class="odd" id="anchors.verticalCenter-prop"><td class="tblQmlPropNode"><p><a name="anchors.verticalCenter-prop"></a><span class="name">anchors.verticalCenter</span> : <span class="type">AnchorLine</span></p></td></tr><tr valign="top" class="odd" id="anchors.baseline-prop"><td class="tblQmlPropNode"><p><a name="anchors.baseline-prop"></a><span class="name">anchors.baseline</span> : <span class="type">AnchorLine</span></p></td></tr></table></div></div><div class="qmldoc"><p>These properties change the respective anchors of the item.</p> <p>To reset an anchor you can assign <code>undefined</code>:</p> <pre class="qml"> <span class="type"><a href="qml-qtquick-anchorchanges.html">AnchorChanges</a></span> { <span class="name">target</span>: <span class="name">myItem</span> <span class="name">anchors</span>.left: <span class="name">undefined</span> <span class="comment">//remove myItem's left anchor</span> <span class="name">anchors</span>.right: <span class="name">otherItem</span>.<span class="name">right</span> } </pre> </div></div><!-- @@@anchors --> <br/> <!-- $$$target --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="target-prop"> <td class="tblQmlPropNode"><p> <a name="target-prop"></a><span class="name">target</span> : <span class="type"><a href="qml-qtquick-item.html">Item</a></span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds the <a href="qml-qtquick-item.html">Item</a> for which the anchor changes will be applied.</p> </div></div><!-- @@@target --> <br/> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2017 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>