Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > d5e62c01ae8d1e579463c6a871dd44bf > files > 5014

qtbase5-doc-5.12.6-2.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" />
<!-- widgets-tutorial.qdoc -->
  <title>Widgets Tutorial - Child Widgets | Qt Widgets 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="qtwidgets-index.html">Qt Widgets</a></td><td >Widgets Tutorial - Child Widgets</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-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="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Widgets Tutorial - Child Widgets</h1>
<span class="subtitle"></span>
<!-- $$$tutorials/widgets/childwidget-description -->
<div class="descr"> <a name="details"></a>
<p>We can add a child widget to the window created in the previous example by passing <code>window</code> as the parent to its constructor. In this case, we add a button to the window and place it in a specific location:</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;
      window<span class="operator">.</span>resize(<span class="number">320</span><span class="operator">,</span> <span class="number">240</span>);
      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;childwidget&quot;</span><span class="operator">,</span> <span class="string">&quot;Child widget&quot;</span>));
      window<span class="operator">.</span>show();

      <span class="type"><a href="qpushbutton.html">QPushButton</a></span> <span class="operator">*</span>button <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qpushbutton.html">QPushButton</a></span>(
          <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>translate(<span class="string">&quot;childwidget&quot;</span><span class="operator">,</span> <span class="string">&quot;Press me&quot;</span>)<span class="operator">,</span> <span class="operator">&amp;</span>window);
      button<span class="operator">-</span><span class="operator">&gt;</span>move(<span class="number">100</span><span class="operator">,</span> <span class="number">100</span>);
      button<span class="operator">-</span><span class="operator">&gt;</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-childwidget.png" alt="" /></td></tr>
</table></div>
</div><p>The button is now a child of the window and will be deleted when the window is destroyed. Note that hiding or closing the window does not automatically destroy it. It will be destroyed when the example exits.</p>
<p>Files:</p>
<ul>
<li><a href="qtwidgets-tutorials-widgets-childwidget-childwidget-pro.html">tutorials/widgets/childwidget/childwidget.pro</a></li>
<li><a href="qtwidgets-tutorials-widgets-childwidget-main-cpp.html">tutorials/widgets/childwidget/main.cpp</a></li>
</ul>
</div>
<!-- @@@tutorials/widgets/childwidget -->
        </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>