<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qquickrectangle.cpp --> <title>Rectangle 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 >Rectangle 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> <li class="level2"><a href="#appearance">Appearance</a></li> <li class="level2"><a href="#example-usage">Example Usage</a></li> <li class="level2"><a href="#performance">Performance</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">Rectangle QML Type</h1> <span class="subtitle"></span> <!-- $$$Rectangle-brief --> <p>Paints a filled rectangle with an optional border <a href="#details">More...</a></p> <!-- @@@Rectangle --> <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><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <p><a href="qml-qtquick-item.html">Item</a></p> </td></tr></table></div><ul> <li><a href="qml-qtquick-rectangle-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-rectangle.html#antialiasing-prop">antialiasing</a></b></b> : bool</li> <li class="fn"><b><b><a href="qml-qtquick-rectangle.html#border-prop">border</a></b></b><ul> <li class="fn"><b><b><a href="qml-qtquick-rectangle.html#border.width-prop">border.width</a></b></b> : int</li> <li class="fn"><b><b><a href="qml-qtquick-rectangle.html#border.color-prop">border.color</a></b></b> : color</li> </ul> </li> <li class="fn"><b><b><a href="qml-qtquick-rectangle.html#color-prop">color</a></b></b> : color</li> <li class="fn"><b><b><a href="qml-qtquick-rectangle.html#gradient-prop">gradient</a></b></b> : Gradient</li> <li class="fn"><b><b><a href="qml-qtquick-rectangle.html#radius-prop">radius</a></b></b> : real</li> </ul> <!-- $$$Rectangle-description --> <a name="details"></a> <h2 id="details">Detailed Description</h2> <p>Rectangle items are used to fill areas with solid color or gradients, and/or to provide a rectangular border.</p> <a name="appearance"></a> <h2 id="appearance">Appearance</h2> <p>Each Rectangle item is painted using either a solid fill color, specified using the <a href="qml-qtquick-rectangle.html#color-prop">color</a> property, or a gradient, defined using a Gradient type and set using the <a href="qml-qtquick-rectangle.html#gradient-prop">gradient</a> property. If both a color and a gradient are specified, the gradient is used.</p> <p>You can add an optional border to a rectangle with its own color and thickness by setting the <a href="qml-qtquick-rectangle.html#border.color-prop">border.color</a> and <a href="qml-qtquick-rectangle.html#border.width-prop">border.width</a> properties. Set the color to "transparent" to paint a border without a fill color.</p> <p>You can also create rounded rectangles using the <a href="qml-qtquick-rectangle.html#radius-prop">radius</a> property. Since this introduces curved edges to the corners of a rectangle, it may be appropriate to set the <a href="qml-qtquick-item.html#antialiasing-prop">Item::antialiasing</a> property to improve its appearance.</p> <a name="example-usage"></a> <h2 id="example-usage">Example Usage</h2> <div class="float-right"><p><img src="images/declarative-rect.png" alt="" /></p> </div><p>The following example shows the effects of some of the common properties on a Rectangle item, which in this case is used to create a square:</p> <pre class="qml"> import QtQuick 2.0 <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></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="name">border</span>.color: <span class="string">"black"</span> <span class="name">border</span>.width: <span class="number">5</span> <span class="name">radius</span>: <span class="number">10</span> } </pre> <br style="clear: both" /><a name="performance"></a> <h2 id="performance">Performance</h2> <p>Using the <a href="qml-qtquick-item.html#antialiasing-prop">Item::antialiasing</a> property improves the appearance of a rounded rectangle at the cost of rendering performance. You should consider unsetting this property for rectangles in motion, and only set it when they are stationary.</p> <p><b>See also </b><a href="qtquick-imageelements-example.html#image">Image</a>.</p> <!-- @@@Rectangle --> <h2>Property Documentation</h2> <!-- $$$antialiasing --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="antialiasing-prop"> <td class="tblQmlPropNode"><p> <a name="antialiasing-prop"></a><span class="name">antialiasing</span> : <span class="type">bool</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>Used to decide if the Rectangle should use antialiasing or not. <a href="qtquick-visualcanvas-scenegraph-renderer.html#antialiasing">Antialiasing</a> provides information on the performance implications of this property.</p> <p>The default is true for Rectangles with a radius, and false otherwise.</p> </div></div><!-- @@@antialiasing --> <br/> <!-- $$$border --> <div class="qmlitem"><div class="qmlproto"><div class="table"><table class="qmlname"><tr valign="top" class="even" id="border-prop"><th class="centerAlign"><p><a name="border-prop"></a><b>border group</b></p></th></tr><tr valign="top" class="odd" id="border.width-prop"><td class="tblQmlPropNode"><p><a name="border.width-prop"></a><span class="name">border.width</span> : <span class="type">int</span></p></td></tr><tr valign="top" class="odd" id="border.color-prop"><td class="tblQmlPropNode"><p><a name="border.color-prop"></a><span class="name">border.color</span> : <span class="type">color</span></p></td></tr></table></div></div><div class="qmldoc"><p>The width and color used to draw the border of the rectangle.</p> <p>A width of 1 creates a thin line. For no line, use a width of 0 or a transparent color.</p> <p><b>Note: </b>The width of the rectangle's border does not affect the geometry of the rectangle itself or its position relative to other items if anchors are used.</p><p>The border is rendered within the rectangle's boundaries.</p> </div></div><!-- @@@border --> <br/> <!-- $$$color --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="color-prop"> <td class="tblQmlPropNode"><p> <a name="color-prop"></a><span class="name">color</span> : <span class="type">color</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds the color used to fill the rectangle.</p> <p>The default color is white.</p> <div class="float-right"><p><img src="images/rect-color.png" alt="" /></p> </div><p>The following example shows rectangles with colors specified using hexadecimal and named color notation:</p> <pre class="qml"> <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> { <span class="name">color</span>: <span class="string">"#00B000"</span> <span class="name">width</span>: <span class="number">80</span>; <span class="name">height</span>: <span class="number">80</span> } <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> { <span class="name">color</span>: <span class="string">"steelblue"</span> <span class="name">y</span>: <span class="number">100</span>; <span class="name">width</span>: <span class="number">80</span>; <span class="name">height</span>: <span class="number">80</span> } </pre> <br style="clear: both" /><p>If both a gradient and a color are specified, the gradient will be used.</p> <p><b>See also </b><a href="qml-qtquick-rectangle.html#gradient-prop">gradient</a>.</p> </div></div><!-- @@@color --> <br/> <!-- $$$gradient --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="gradient-prop"> <td class="tblQmlPropNode"><p> <a name="gradient-prop"></a><span class="name">gradient</span> : <span class="type"><a href="qml-qtquick-gradient.html">Gradient</a></span></p></td></tr> </table></div> </div><div class="qmldoc"><p>The gradient to use to fill the rectangle.</p> <p>This property allows for the construction of simple vertical gradients. Other gradients may be formed by adding rotation to the rectangle.</p> <div class="float-left"><p><img src="images/declarative-rect_gradient.png" alt="" /></p> </div><pre class="qml"> <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> { <span class="name">y</span>: <span class="number">0</span>; <span class="name">width</span>: <span class="number">80</span>; <span class="name">height</span>: <span class="number">80</span> <span class="name">color</span>: <span class="string">"lightsteelblue"</span> } <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> { <span class="name">y</span>: <span class="number">100</span>; <span class="name">width</span>: <span class="number">80</span>; <span class="name">height</span>: <span class="number">80</span> <span class="name">gradient</span>: <span class="name">Gradient</span> { <span class="type"><a href="qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">0.0</span>; <span class="name">color</span>: <span class="string">"lightsteelblue"</span> } <span class="type"><a href="qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">1.0</span>; <span class="name">color</span>: <span class="string">"blue"</span> } } } <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> { <span class="name">y</span>: <span class="number">200</span>; <span class="name">width</span>: <span class="number">80</span>; <span class="name">height</span>: <span class="number">80</span> <span class="name">rotation</span>: <span class="number">90</span> <span class="name">gradient</span>: <span class="name">Gradient</span> { <span class="type"><a href="qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">0.0</span>; <span class="name">color</span>: <span class="string">"lightsteelblue"</span> } <span class="type"><a href="qml-qtquick-gradientstop.html">GradientStop</a></span> { <span class="name">position</span>: <span class="number">1.0</span>; <span class="name">color</span>: <span class="string">"blue"</span> } } } </pre> <br style="clear: both" /><p>If both a gradient and a color are specified, the gradient will be used.</p> <p><b>See also </b><a href="qml-qtquick-gradient.html">Gradient</a> and <a href="qml-qtquick-rectangle.html#color-prop">color</a>.</p> </div></div><!-- @@@gradient --> <br/> <!-- $$$radius --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="radius-prop"> <td class="tblQmlPropNode"><p> <a name="radius-prop"></a><span class="name">radius</span> : <span class="type">real</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds the corner radius used to draw a rounded rectangle.</p> <p>If radius is non-zero, the rectangle will be painted as a rounded rectangle, otherwise it will be painted as a normal rectangle. The same radius is used by all 4 corners; there is currently no way to specify different radii for different corners.</p> </div></div><!-- @@@radius --> <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>