<?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>Gradient QML Type | 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 ><a href="qtquick-qmlmodule.html">QML Types</a></td><td >Gradient QML Type</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="#properties">Properties</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> <li class="level2"><a href="#example-usage">Example Usage</a></li> <li class="level2"><a href="#performance-and-limitations">Performance and Limitations</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">Gradient QML Type</h1> <span class="subtitle"></span> <!-- $$$Gradient-brief --> <p>Defines a gradient fill. <a href="#details">More...</a></p> <!-- @@@Gradient --> <div class="table"><table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> Import Statement:</td><td class="memItemRight bottomAlign"> import QtQuick 2.12</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherited By:</td><td class="memItemRight bottomAlign"> <p><a href="qml-qtquick-shapes-shapegradient.html">ShapeGradient</a></p> </td></tr></table></div><ul> <li><a href="qml-qtquick-gradient-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-gradient.html#orientation-prop">orientation</a></b></b> : enumeration</li> <li class="fn"><b><b><a href="qml-qtquick-gradient.html#stops-prop">stops</a></b></b> : list<GradientStop></li> </ul> <!-- $$$Gradient-description --> <a name="details"></a> <h2 id="details">Detailed Description</h2> <p>A gradient is defined by two or more colors, which will be blended seamlessly.</p> <p>The colors are specified as a set of <a href="qml-qtquick-gradientstop.html">GradientStop</a> child items, each of which defines a position on the gradient from 0.0 to 1.0 and a color. The position of each <a href="qml-qtquick-gradientstop.html">GradientStop</a> is defined by setting its <a href="qml-qtquick-gradientstop.html#position-prop">position</a> property; its color is defined using its <a href="qml-qtquick-gradientstop.html#color-prop">color</a> property.</p> <p>A gradient without any gradient stops is rendered as a solid white fill.</p> <p>Note that this item is not a visual representation of a gradient. To display a gradient, use a visual item (like <a href="qml-qtquick-rectangle.html">Rectangle</a>) which supports the use of gradients.</p> <a name="example-usage"></a> <h2 id="example-usage">Example Usage</h2> <div class="float-right"><p><img src="images/qml-gradient.png" alt="" /></p> </div><p>The following example declares a <a href="qml-qtquick-rectangle.html">Rectangle</a> item with a gradient starting with red, blending to yellow at one third of the height of the rectangle, and ending with green:</p> <pre class="qml"> Rectangle { width: 100; height: 100 gradient: Gradient { GradientStop { position: 0.0; color: "red" } GradientStop { position: 0.33; color: "yellow" } GradientStop { position: 1.0; color: "green" } } } </pre> <br style="clear: both" /><a name="performance-and-limitations"></a> <h2 id="performance-and-limitations">Performance and Limitations</h2> <p>Calculating gradients can be computationally expensive compared to the use of solid color fills or images. Consider using gradients for static items in a user interface.</p> <p>Since Qt 5.12, vertical and horizontal linear gradients can be applied to items. If you need to apply angled gradients, a combination of rotation and clipping can be applied to the relevant items. Alternatively, consider using <a href="qtquick-module.html">QtQuick</a>.Shapes::LinearGradient or QtGraphicalEffects::LinearGradient. These approaches can all introduce additional performance requirements for your application.</p> <p>The use of animations involving gradient stops may not give the desired result. An alternative way to animate gradients is to use pre-generated images or SVG drawings containing gradients.</p> <p><b>See also </b><a href="qml-qtquick-gradientstop.html">GradientStop</a>.</p> <!-- @@@Gradient --> <h2>Property Documentation</h2> <!-- $$$orientation --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="orientation-prop"> <td class="tblQmlPropNode"><p> <a name="orientation-prop"></a><span class="name">orientation</span> : <span class="type">enumeration</span></p></td></tr> </table></div> </div><div class="qmldoc"><p>Set this property to define the direction of the gradient.</p> <ul> <li>Gradient.Vertical - a vertical gradient</li> <li>Gradient.Horizontal - a horizontal gradient</li> </ul> <p>The default is Gradient.Vertical.</p> <p>This property was introduced in Qt 5.12.</p> </div></div><!-- @@@orientation --> <br/> <!-- $$$stops --> <div class="qmlitem"><div class="qmlproto"> <div class="table"><table class="qmlname"> <tr valign="top" class="odd" id="stops-prop"> <td class="tblQmlPropNode"><p> <a name="stops-prop"></a><span class="qmldefault">[default] </span><span class="name">stops</span> : <span class="type">list</span><<span class="type"><a href="qml-qtquick-gradientstop.html">GradientStop</a></span>></p></td></tr> </table></div> </div><div class="qmldoc"><p>This property holds the gradient stops describing the gradient.</p> <p>By default, this property contains an empty list.</p> <p>To set the gradient stops, define them as children of the Gradient.</p> </div></div><!-- @@@stops --> <br/> </div> </div> </div> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</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>