Sophie

Sophie

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

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" />
<!-- qtquicklayouts-overview.qdoc -->
  <title>Qt Quick Layouts Overview | 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 >Qt Quick Layouts Overview</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="#getting-started">Getting Started</a></li>
<li class="level1"><a href="#key-features">Key Features</a></li>
<li class="level1"><a href="#a-simple-layout">A Simple Layout</a></li>
<li class="level2"><a href="#size-constraints">Size Constraints</a></li>
<li class="level2"><a href="#specifying-preferred-size">Specifying Preferred Size</a></li>
<li class="level1"><a href="#connecting-windows-and-layouts">Connecting Windows and Layouts</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt Quick Layouts Overview</h1>
<span class="subtitle"></span>
<!-- $$$qtquicklayouts-overview.html-description -->
<div class="descr"> <a name="details"></a>
<p>Qt Quick Layouts are items that are used to arrange items in a user interface. Since Qt Quick Layouts also resize their items, they are well suited for resizable user interfaces.</p>
<a name="getting-started"></a>
<h2 id="getting-started">Getting Started</h2>
<p>The QML types can be imported into your application using the following import statement in your <code>.qml</code> file.</p>
<pre class="cpp">

  import <span class="type"><a href="qtquick-module.html">QtQuick</a></span><span class="operator">.</span>Layouts <span class="number">1.11</span>

</pre>
<a name="key-features"></a>
<h2 id="key-features">Key Features</h2>
<p>Some of the key features are:</p>
<ul>
<li><a href="qml-qtquick-layouts-layout.html#alignment-attached-prop">Alignment</a> of items can be specified with the <a href="qml-qtquick-layouts-layout.html#alignment-attached-prop">Layout.alignment</a> property</li>
<li><a href="qml-qtquick-layouts-layout.html#fillWidth-attached-prop">Resizable items</a> can be specified with the <a href="qml-qtquick-layouts-layout.html#fillWidth-attached-prop">Layout.fillWidth</a> and <a href="qml-qtquick-layouts-layout.html#fillHeight-attached-prop">Layout.fillHeight</a> properties.</li>
<li><a href="qtquicklayouts-overview.html#size-constraints">Size constraints</a> can be specified with <a href="qml-qtquick-layouts-layout.html#minimumWidth-attached-prop">Layout.minimumWidth</a>, <a href="qml-qtquick-layouts-layout.html#preferredWidth-attached-prop">Layout.preferredWidth</a>, and <a href="qml-qtquick-layouts-layout.html#maximumWidth-attached-prop">Layout.maximumWidth</a> properties (&quot;Width&quot; can be replaced with &quot;Height&quot; for specifying similar constraints to the height).</li>
<li><a href="qml-qtquick-layouts-rowlayout.html#spacing-prop">Spacings</a> can be specified with <a href="qml-qtquick-layouts-rowlayout.html#spacing-prop">spacing</a>, <a href="qml-qtquick-layouts-gridlayout.html#rowSpacing-prop">rowSpacing</a> or <a href="qml-qtquick-layouts-gridlayout.html#columnSpacing-prop">columnSpacing</a></li>
</ul>
<p>In addition to the above features, <a href="qml-qtquick-layouts-gridlayout.html">GridLayout</a> adds these features:</p>
<ul>
<li><a href="qml-qtquick-layouts-layout.html#row-attached-prop">Grid coordinates</a> can be specified with the <a href="qml-qtquick-layouts-layout.html#row-attached-prop">Layout.row</a> and <a href="qml-qtquick-layouts-layout.html#column-attached-prop">Layout.column</a> properties.</li>
<li><a href="qml-qtquick-layouts-gridlayout.html#flow-prop">Automatic grid coordinates</a> used together with the <a href="qml-qtquick-layouts-gridlayout.html#flow-prop">flow</a>, <a href="qml-qtquick-layouts-gridlayout.html#rows-prop">rows</a>, and <a href="qml-qtquick-layouts-gridlayout.html#columns-prop">columns</a> properties.</li>
<li><a href="qml-qtquick-layouts-layout.html#columnSpan-attached-prop">Spans</a> across rows or columns can be specified with the <a href="qml-qtquick-layouts-layout.html#rowSpan-attached-prop">Layout.rowSpan</a> and <a href="qml-qtquick-layouts-layout.html#columnSpan-attached-prop">Layout.columnSpan</a> properties.</li>
</ul>
<a name="a-simple-layout"></a>
<h2 id="a-simple-layout">A Simple Layout</h2>
<pre class="qml">

  Window {
      RowLayout {
          anchors.fill: parent
          spacing: 6
          Rectangle {
              color: 'azure'
              Layout.preferredWidth: 100
              Layout.preferredHeight: 150
          }
          Rectangle {
              color: "plum"
              Layout.fillWidth: true
              Layout.fillHeight: true
          }
      }
  }

</pre>
<p>As the intention of using a layout is to rearrange its children whenever the layout changes size, the application should make sure that the layout gets resized. In the above snippet the <a href="qml-qtquick-layouts-rowlayout.html">RowLayout</a> ensures that by specifying <code>anchors.fill: parent</code>. However, it can also be by other means, such as directly specifying <a href="qml-qtquick-item.html#width-prop">width</a> and <a href="qml-qtquick-item.html#height-prop">height</a> properties. In the same snippet, the <code>azure</code> Rectangle has a fixed size of <code>(100, 150)</code> pixels, and the <code>plum</code> Rectangle will expand to occupy all the space it gets allocated.</p>
<p><b>Note: </b>A layout is responsible for its children's geometry. You should therefore not specify <a href="qml-qtquick-item.html#width-prop">width</a>, <a href="qml-qtquick-item.html#height-prop">height</a>, <a href="qml-qtquick-item.html#x-prop">x</a>, <a href="qml-qtquick-item.html#y-prop">y</a> or any other properties that might influence those properties (such as <a href="qml-qtquick-item.html#anchors-prop">anchors</a>) on those items. Otherwise there would be a conflict of interest, and the result is undefined. This is also the case if the child item is a layout. Therefore, only layouts with no parent layout can have <code>anchors.fill: parent</code>.</p><p>All items in the layout will have 6 pixels of spacing between them:</p>
<pre class="qml">

  spacing: 6

</pre>
<a name="size-constraints"></a>
<h3 id="size-constraints">Size Constraints</h3>
<p>Since an item can be resized by its layout, the layout needs to know the <a href="qml-qtquick-layouts-layout.html#minimumWidth-attached-prop">minimum</a>, <a href="qml-qtquick-layouts-layout.html#preferredWidth-attached-prop">preferred</a>, and <a href="qml-qtquick-layouts-layout.html#maximumWidth-attached-prop">maximum</a> sizes of all items where <a href="qml-qtquick-layouts-layout.html#fillWidth-attached-prop">Layout.fillWidth</a> or <a href="qml-qtquick-layouts-layout.html#fillHeight-attached-prop">Layout.fillHeight</a> is set to <code>true</code>. For instance, the following will produce a layout with two rectangles lying side-by-side that stretches horizontally. The azure rectangle can be resized from 50x150 to 300x150, and the plum rectangle can be resized from 100x100 to ∞x100.</p>
<pre class="qml">

  RowLayout {
      id: layout
      anchors.fill: parent
      spacing: 6
      Rectangle {
          color: 'azure'
          Layout.fillWidth: true
          Layout.minimumWidth: 50
          Layout.preferredWidth: 100
          Layout.maximumWidth: 300
          Layout.minimumHeight: 150
          Text {
              anchors.centerIn: parent
              text: parent.width + 'x' + parent.height
          }
      }
      Rectangle {
          color: 'plum'
          Layout.fillWidth: true
          Layout.minimumWidth: 100
          Layout.preferredWidth: 200
          Layout.preferredHeight: 100
          Text {
              anchors.centerIn: parent
              text: parent.width + 'x' + parent.height
          }
      }
  }

</pre>
<p class="centerAlign"><img src="images/rowlayout-minimum.png" alt="&quot;RowLayout at its minimum&quot;" /></p><p>Combining each item's constraints will give these implicit constraints to the layout element:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th ></th><th >minimum</th><th >preferred</th><th >maximum</th></tr></thead>
<tr valign="top" class="odd"><td >implicit constraints (width)</td><td >156</td><td >306</td><td >∞ (<code>Number.POSITIVE_INFINITY</code>)</td></tr>
<tr valign="top" class="even"><td >implicit constraints (heights)</td><td >150</td><td >150</td><td >150</td></tr>
</table></div>
<p>Thus, the layout cannot be narrower than 156 or be taller or shorter than 150 without breaking any of the constraints of its child items.</p>
<a name="specifying-preferred-size"></a>
<h3 id="specifying-preferred-size">Specifying Preferred Size</h3>
<p>For each item, the effective preferred size may come from one of several candidate properties. For determining the effective preferred size, it will query these candidate properties in the following order, and use the first candidate with a valid width or height.</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Candidate properties</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td ><a href="qml-qtquick-layouts-layout.html#preferredWidth-attached-prop">Layout.preferredWidth</a> or <a href="qml-qtquick-layouts-layout.html#preferredHeight-attached-prop">Layout.preferredHeight</a></td><td >These properties are supposed to be modified by the application if the default implicit size does not give the optimal arrangement.</td></tr>
<tr valign="top" class="even"><td ><a href="qml-qtquick-item.html#implicitWidth-prop">implicitWidth</a> or <a href="qml-qtquick-item.html#implicitHeight-prop">implicitHeight</a></td><td >These properties are supposed to be supplied by each item to give a meaningful ideal size, for example the size needed to display all the contents of a <a href="qml-qtquick-text.html">Text</a> type. An implicit width or height of <code>0</code> is interpreted as invalid.</td></tr>
<tr valign="top" class="odd"><td ><a href="qml-qtquick-item.html#width-prop">width</a> and <a href="qml-qtquick-item.html#height-prop">height</a></td><td >If none of the above properties are valid, the layout will resort to the <a href="qml-qtquick-item.html#width-prop">width</a> and <a href="qml-qtquick-item.html#height-prop">height</a> properties.</td></tr>
</table></div>
<p>An item can specify <a href="qml-qtquick-layouts-layout.html#preferredWidth-attached-prop">Layout.preferredWidth</a> without having to specify <a href="qml-qtquick-layouts-layout.html#preferredHeight-attached-prop">Layout.preferredHeight</a>. In this case, the effective preferred height will be determined from the <a href="qml-qtquick-item.html#implicitHeight-prop">implicitHeight</a> (or ultimately <a href="qml-qtquick-item.html#height-prop">height</a>).</p>
<p><b>Note: </b>Resorting to <a href="qml-qtquick-item.html#width-prop">width</a> or <a href="qml-qtquick-item.html#height-prop">height</a> properties is only provided as a final fallback. If you want to override the preferred size, it is recommended to use <a href="qml-qtquick-layouts-layout.html#preferredWidth-attached-prop">Layout.preferredWidth</a> or <a href="qml-qtquick-layouts-layout.html#preferredHeight-attached-prop">Layout.preferredHeight</a>. Relying on the <a href="qml-qtquick-item.html#width-prop">width</a> or <a href="qml-qtquick-item.html#height-prop">height</a> properties for specifying the preferred size might give some unexpected behavior. For instance, changing the <a href="qml-qtquick-item.html#width-prop">width</a> or <a href="qml-qtquick-item.html#height-prop">height</a> properties won't trigger a layout rearrangement. Also, when the layout is forced to do a full rebuild it might use the actual width and height, and not the width and height specified in the QML file.</p><a name="connecting-windows-and-layouts"></a>
<h2 id="connecting-windows-and-layouts">Connecting Windows and Layouts</h2>
<p>You can just use normal anchoring concepts to ensure that the layout will follow the window resizing.</p>
<pre class="qml">

  RowLayout {
      id: layout
      anchors.fill: parent

</pre>
<p>The size constraints of layouts can be used to ensure that the window cannot be resized beyond the layout constraints. You can take the size constraints from the layout and set these constraints on the minimumWidth, minimumHeight, maximumWidth, and maximumHeight of the Window element. The following code ensures that the window cannot be resized beyond the constraints of the layout:</p>
<pre class="qml">

  minimumWidth: layout.Layout.minimumWidth
  minimumHeight: layout.Layout.minimumHeight
  maximumWidth: 1000
  maximumHeight: layout.Layout.maximumHeight

</pre>
<p><b>Note: </b>Since layout.Layout.maximumWidth is infinite in this case, we cannot bind that to the maximumWidth property of Window, since that is an integer number. We therefore set a fixed maximum width to 1000.</p><p>Finally, you usually want the initial size of the window to be the layout's implicit size:</p>
<pre class="qml">

  width: layout.implicitWidth
  height: layout.implicitHeight

</pre>
</div>
<!-- @@@qtquicklayouts-overview.html -->
        </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>