Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-updates > by-pkgid > 6e2327ca1c896c6d674ae53117299f21 > files > 1218

qtdeclarative5-doc-5.12.6-1.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- tutorial.qdoc -->
  <title>QML Tutorial 1 - Basic Types | 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 >QML Tutorial 1 - Basic Types</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">
  <link rel="prev" href="qml-tutorial.html" />
  <link rel="next" href="qml-tutorial2.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="qml-tutorial.html">QML Tutorial</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="qml-tutorial2.html">QML Tutorial 2 - QML Components</a>
</p><p/>
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#walkthrough">Walkthrough</a></li>
<li class="level2"><a href="#import">Import</a></li>
<li class="level2"><a href="#rectangle-type">Rectangle Type</a></li>
<li class="level2"><a href="#text-type">Text Type</a></li>
<li class="level2"><a href="#viewing-the-example">Viewing the Example</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QML Tutorial 1 - Basic Types</h1>
<span class="subtitle"></span>
<!-- $$$qml-tutorial1.html-description -->
<div class="descr"> <a name="details"></a>
<p>This first program is a very simple &quot;Hello world&quot; example that introduces some basic QML concepts. The picture below is a screenshot of this program.</p>
<p class="centerAlign"><img src="images/declarative-tutorial1.png" alt="" /></p><p>Here is the QML code for the application:</p>
<pre class="qml">

  import QtQuick 2.0

  Rectangle {
      id: page
      width: 320; height: 480
      color: "lightgray"

      Text {
          id: helloText
          text: "Hello world!"
          y: 30
          anchors.horizontalCenter: page.horizontalCenter
          font.pointSize: 24; font.bold: true
      }
  }

</pre>
<a name="walkthrough"></a>
<h2 id="walkthrough">Walkthrough</h2>
<a name="import"></a>
<h3 id="import">Import</h3>
<p>First, we need to import the types that we need for this example. Most QML files will import the built-in QML types (like <a href="qml-qtquick-rectangle.html">Rectangle</a>, <a href="qml-qtquick-image.html">Image</a>, ..&#x2e;) that come with Qt, using:</p>
<pre class="qml">

  import QtQuick 2.0

</pre>
<a name="rectangle-type"></a>
<h3 id="rectangle-type">Rectangle Type</h3>
<pre class="qml">

  Rectangle {
      id: page
      width: 320; height: 480
      color: "lightgray"

</pre>
<p>We declare a root object of type <a href="qml-qtquick-rectangle.html">Rectangle</a>. It is one of the basic building blocks you can use to create an application in QML. We give it an <code>id</code> to be able to refer to it later. In this case, we call it &quot;page&quot;. We also set the <code>width</code>, <code>height</code> and <code>color</code> properties. The <a href="qml-qtquick-rectangle.html">Rectangle</a> type contains many other properties (such as <code>x</code> and <code>y</code>), but these are left at their default values.</p>
<a name="text-type"></a>
<h3 id="text-type">Text Type</h3>
<pre class="qml">

      Text {
          id: helloText
          text: "Hello world!"
          y: 30
          anchors.horizontalCenter: page.horizontalCenter
          font.pointSize: 24; font.bold: true
      }

</pre>
<p>We add a <a href="qml-qtquick-text.html">Text</a> type as a child of the root Rectangle type that displays the text 'Hello world!'.</p>
<p>The <code>y</code> property is used to position the text vertically at 30 pixels from the top of its parent.</p>
<p>The <code>anchors.horizontalCenter</code> property refers to the horizontal center of an type. In this case, we specify that our text type should be horizontally centered in the <i>page</i> element (see <a href="qtquick-positioning-anchors.html">Anchor-Based Layout</a>).</p>
<p>The <code>font.pointSize</code> and <code>font.bold</code> properties are related to fonts and use the dot notation.</p>
<a name="viewing-the-example"></a>
<h3 id="viewing-the-example">Viewing the Example</h3>
<p>To view what you have created, run the qmlscene tool (located in the <code>bin</code> directory) with your filename as the first argument. For example, to run the provided completed Tutorial 1 example from the install location, you would type:</p>
<pre class="cpp">

  qmlscene tutorials<span class="operator">/</span>helloworld<span class="operator">/</span>tutorial1<span class="operator">.</span>qml

</pre>
</div>
<!-- @@@qml-tutorial1.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="qml-tutorial.html">QML Tutorial</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="qml-tutorial2.html">QML Tutorial 2 - QML Components</a>
</p>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</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>