<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- text.qdoc --> <title>Qt Quick Examples - Text | 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 >Qt Quick Examples - Text</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="#hello">Hello</a></li> <li class="level1"><a href="#fonts">Fonts</a></li> <li class="level1"><a href="#available-fonts">Available Fonts</a></li> <li class="level1"><a href="#banner">Banner</a></li> <li class="level1"><a href="#img-tag">Img Tag</a></li> <li class="level1"><a href="#text-layout">Text Layout</a></li> </ul> </div> <div class="sidebar-content" id="sidebar-content"></div></div> <h1 class="title">Qt Quick Examples - Text</h1> <span class="subtitle"></span> <!-- $$$text-description --> <div class="descr"> <a name="details"></a> <p class="centerAlign"><img src="images/qml-text-example.png" alt="" /></p><p><i>Text</i> is a collection of small QML examples relating to text. Each example is a small QML file, usually containing or emphasizing a particular type or feature. You can run and observe the behavior of each example.</p> <a name="hello"></a> <h2 id="hello">Hello</h2> <p><i>Hello</i> shows how to change and animate the letter spacing of a <a href="qml-qtquick-text.html">Text</a> type. It uses a sequential animation to first animate the font.letterSpacing property from <code>0</code> to <code>50</code> over three seconds and then move the text to a random position on screen:</p> <pre class="qml"> SequentialAnimation on <span class="name">font</span>.letterSpacing { <span class="name">loops</span>: <span class="name">Animation</span>.<span class="name">Infinite</span>; <span class="type"><a href="qml-qtquick-numberanimation.html">NumberAnimation</a></span> { <span class="name">from</span>: <span class="number">0</span>; <span class="name">to</span>: <span class="number">50</span>; <span class="name">easing</span>.type: <span class="name">Easing</span>.<span class="name">InQuad</span>; <span class="name">duration</span>: <span class="number">3000</span> } <span class="type"><a href="qml-qtquick-scriptaction.html">ScriptAction</a></span> { <span class="name">script</span>: { <span class="name">container</span>.<span class="name">y</span> <span class="operator">=</span> (<span class="name">screen</span>.<span class="name">height</span> <span class="operator">/</span> <span class="number">4</span>) <span class="operator">+</span> (<span class="name">Math</span>.<span class="name">random</span>() <span class="operator">*</span> <span class="name">screen</span>.<span class="name">height</span> <span class="operator">/</span> <span class="number">2</span>) <span class="name">container</span>.<span class="name">x</span> <span class="operator">=</span> (<span class="name">screen</span>.<span class="name">width</span> <span class="operator">/</span> <span class="number">4</span>) <span class="operator">+</span> (<span class="name">Math</span>.<span class="name">random</span>() <span class="operator">*</span> <span class="name">screen</span>.<span class="name">width</span> <span class="operator">/</span> <span class="number">2</span>) } } } </pre> <a name="fonts"></a> <h2 id="fonts">Fonts</h2> <p><i>Fonts</i> shows different ways of using fonts with the <a href="qml-qtquick-text.html">Text</a> type. Simply by name, using the font.family property directly:</p> <pre class="qml"> <span class="name">font</span>.family: <span class="string">"Times"</span> </pre> <p>or using a <a href="qml-qtquick-fontloader.html">FontLoader</a> type:</p> <pre class="qml"> <span class="type"><a href="qml-qtquick-fontloader.html">FontLoader</a></span> { <span class="name">id</span>: <span class="name">fixedFont</span>; <span class="name">name</span>: <span class="string">"Courier"</span> } </pre> <p>or using a <a href="qml-qtquick-fontloader.html">FontLoader</a> and specifying a local font file:</p> <pre class="qml"> <span class="type"><a href="qml-qtquick-fontloader.html">FontLoader</a></span> { <span class="name">id</span>: <span class="name">localFont</span>; <span class="name">source</span>: <span class="string">"content/fonts/tarzeau_ocr_a.ttf"</span> } </pre> <p>or finally using a <a href="qml-qtquick-fontloader.html">FontLoader</a> and specifying a remote font file:</p> <pre class="qml"> <span class="type"><a href="qml-qtquick-fontloader.html">FontLoader</a></span> { <span class="name">id</span>: <span class="name">webFont</span>; <span class="name">source</span>: <span class="string">"http://www.princexml.com/fonts/steffmann/Starburst.ttf"</span> } </pre> <a name="available-fonts"></a> <h2 id="available-fonts">Available Fonts</h2> <p><i>Available Fonts</i> shows how to use the Qt global object and a list view to display all the fonts available on the system. The <a href="qml-qtquick-listview.html">ListView</a> type uses the list of fonts available as its model:</p> <pre class="qml"> <span class="name">model</span>: <span class="name">Qt</span>.<span class="name">fontFamilies</span>() </pre> <p>Inside the delegate, the font family is set with the modelData:</p> <pre class="qml"> <span class="name">font</span>.family: <span class="name">modelData</span> </pre> <a name="banner"></a> <h2 id="banner">Banner</h2> <p><i>Banner</i> is a simple example showing how to create a banner using a row of text types and a <a href="qml-qtquick-numberanimation.html">NumberAnimation</a>.</p> <a name="img-tag"></a> <h2 id="img-tag">Img Tag</h2> <p><i>Img tag</i> shows different ways of displaying images in text objects using the <code><img></code> tag.</p> <a name="text-layout"></a> <h2 id="text-layout">Text Layout</h2> <p><i>Text Layout</i> shows how to create a more complex layout for a text item. This example lays out the text in two columns using the onLineLaidOut handler that allows you to position and resize each line:</p> <pre class="qml"> <span class="name">onLineLaidOut</span>: { <span class="name">line</span>.<span class="name">width</span> <span class="operator">=</span> <span class="name">width</span> <span class="operator">/</span> <span class="number">2</span> <span class="operator">-</span> (<span class="name">margin</span>) <span class="keyword">if</span> (<span class="name">line</span>.<span class="name">y</span> <span class="operator">+</span> <span class="name">line</span>.<span class="name">height</span> <span class="operator">>=</span> <span class="name">height</span>) { <span class="name">line</span>.<span class="name">y</span> <span class="operator">-=</span> <span class="name">height</span> <span class="operator">-</span> <span class="name">margin</span> <span class="name">line</span>.<span class="name">x</span> <span class="operator">=</span> <span class="name">width</span> <span class="operator">/</span> <span class="number">2</span> <span class="operator">+</span> <span class="name">margin</span> } } </pre> <p>Files:</p> <ul> <li><a href="qtquick-text-styledtext-layout-qml.html">text/styledtext-layout.qml</a></li> <li><a href="qtquick-text-text-qml.html">text/text.qml</a></li> <li><a href="qtquick-text-fonts-availablefonts-qml.html">text/fonts/availableFonts.qml</a></li> <li><a href="qtquick-text-fonts-banner-qml.html">text/fonts/banner.qml</a></li> <li><a href="qtquick-text-fonts-fonts-qml.html">text/fonts/fonts.qml</a></li> <li><a href="qtquick-text-fonts-hello-qml.html">text/fonts/hello.qml</a></li> <li><a href="qtquick-text-imgtag-textwithimage-qml.html">text/imgtag/TextWithImage.qml</a></li> <li><a href="qtquick-text-imgtag-imgtag-qml.html">text/imgtag/imgtag.qml</a></li> <li><a href="qtquick-text-textselection-textselection-qml.html">text/textselection/textselection.qml</a></li> <li><a href="qtquick-text-main-cpp.html">text/main.cpp</a></li> <li><a href="qtquick-text-text-pro.html">text/text.pro</a></li> <li><a href="qtquick-text-text-qmlproject.html">text/text.qmlproject</a></li> <li><a href="qtquick-text-text-qrc.html">text/text.qrc</a></li> </ul> </div> <!-- @@@text --> </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>