Sophie

Sophie

distrib > Mageia > 6 > armv5tl > media > core-updates > by-pkgid > 768f7d9f703884aa2562bf0a651086df > files > 4448

qtbase5-doc-5.9.4-1.1.mga6.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" />
<!-- widgets-tutorial.qdoc -->
  <title>Widgets Tutorial - Using Layouts | Qt Widgets 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="qtwidgets-index.html">Qt Widgets</a></td><td >Widgets Tutorial - Using Layouts</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="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Widgets Tutorial - Using Layouts</h1>
<span class="subtitle"></span>
<!-- $$$tutorials/widgets/windowlayout-description -->
<div class="descr"> <a name="details"></a>
<p>Usually, child widgets are arranged inside a window using layout objects rather than by specifying positions and sizes explicitly. Here, we construct a label and line edit widget that we would like to arrange side-by-side.</p>
<div class="qt-code"><div class="table"><table class="generic">
 <tr valign="top" class="odd"><td ><pre class="cpp">

  <span class="preprocessor">#include &lt;QtWidgets&gt;</span>

  <span class="type">int</span> main(<span class="type">int</span> argc<span class="operator">,</span> <span class="type">char</span> <span class="operator">*</span>argv<span class="operator">[</span><span class="operator">]</span>)
  {
      <span class="type"><a href="qapplication.html">QApplication</a></span> app(argc<span class="operator">,</span> argv);
      <span class="type"><a href="qwidget.html">QWidget</a></span> window;
      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>label <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(<span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>translate(<span class="string">&quot;windowlayout&quot;</span><span class="operator">,</span> <span class="string">&quot;Name:&quot;</span>));
      <span class="type"><a href="qlineedit.html">QLineEdit</a></span> <span class="operator">*</span>lineEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>();

      <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span>();
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(label);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(lineEdit);
      window<span class="operator">.</span>setLayout(layout);
      window<span class="operator">.</span>setWindowTitle(
          <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>translate(<span class="string">&quot;windowlayout&quot;</span><span class="operator">,</span> <span class="string">&quot;Window layout&quot;</span>));
      window<span class="operator">.</span>show();
      <span class="keyword">return</span> app<span class="operator">.</span>exec();
  }

</pre>
</td></tr>
<tr valign="top" class="even"><td ><img src="images/widgets-tutorial-windowlayout.png" alt="" /></td></tr>
</table></div>
</div><p>The <code>layout</code> object we construct manages the positions and sizes of widgets supplied to it with the <a href="qboxlayout.html#addWidget">addWidget()</a> function. The layout itself is supplied to the window itself in the call to <a href="qwidget.html#setLayout">setLayout()</a>. Layouts are only visible through the effects they have on the widgets (and other layouts) they are responsible for managing.</p>
<p>In the example above, the ownership of each widget is not immediately clear. Since we construct the widgets and the layout without parent objects, we would expect to see an empty window and two separate windows containing a label and a line edit. However, when we tell the layout to manage the label and line edit and set the layout on the window, both the widgets and the layout itself are ''reparented'' to become children of the window.</p>
<p>Files:</p>
<ul>
<li><a href="qtwidgets-tutorials-widgets-windowlayout-main-cpp.html">tutorials/widgets/windowlayout/main.cpp</a></li>
<li><a href="qtwidgets-tutorials-widgets-windowlayout-windowlayout-pro.html">tutorials/widgets/windowlayout/windowlayout.pro</a></li>
</ul>
</div>
<!-- @@@tutorials/widgets/windowlayout -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</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>