1
<?xml version="1.0" encoding="iso-8859-1"?>
3
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
<!-- widgets-tutorial.qdoc -->
7
<title>Qt 4.6: Widgets Tutorial - Child Widgets</title>
8
<link rel="prev" href="tutorials-widgets-toplevel.html" />
9
<link rel="contents" href="widgets-tutorial.html" />
10
<link rel="next" href="tutorials-widgets-windowlayout.html" />
11
<link href="classic.css" rel="stylesheet" type="text/css" />
14
<table border="0" cellpadding="0" cellspacing="0" width="100%">
16
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
17
<td width="1"> </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="functions.html"><font color="#004faf">All Functions</font></a> · <a href="overviews.html"><font color="#004faf">Overviews</font></a></td><td class="searchBar" align="right" valign="center"><form action="http://www.google.com/cse" id="cse-search-box"><div><input type="hidden" name="cx" value="000136343326384750312:dhbxnqlakyu" /><input type="hidden" name="ie" value="UTF-8" /><input type="text" name="q" size="31" /><input type="submit" name="sa" value="Search" /></div></form></td>
19
[Previous: <a href="tutorials-widgets-toplevel.html">Widgets Tutorial - Creating a Window</a>]
20
[<a href="widgets-tutorial.html">Contents</a>]
21
[Next: <a href="tutorials-widgets-windowlayout.html">Widgets Tutorial - Using Layouts</a>]
23
<h1 class="title">Widgets Tutorial - Child Widgets<br /><span class="subtitle"></span>
27
<li><a href="tutorials-widgets-childwidget-main-cpp.html">tutorials/widgets/childwidget/main.cpp</a></li>
28
<li><a href="tutorials-widgets-childwidget-childwidget-pro.html">tutorials/widgets/childwidget/childwidget.pro</a></li>
30
<p>We can add a child widget to the window created in the previous example by passing <tt>window</tt> as the parent to its constructor. In this case, we add a button to the window and place it in a specific location:</p>
31
<table align="left" width="100%">
32
<tr class="qt-code"><td>
33
<pre> #include <QtGui>
35
int main(int argc, char *argv[])
37
QApplication app(argc, argv);
39
window.resize(320, 240);
40
window.setWindowTitle(QApplication::translate("childwidget", "Child widget"));
43
QPushButton *button = new QPushButton(
44
QApplication::translate("childwidget", "Press me"), &window);
45
button->move(100, 100);
49
</td><td align="right">
50
<p><img src="images/widgets-tutorial-childwidget.png" /></p>
53
<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>
55
[Previous: <a href="tutorials-widgets-toplevel.html">Widgets Tutorial - Creating a Window</a>]
56
[<a href="widgets-tutorial.html">Contents</a>]
57
[Next: <a href="tutorials-widgets-windowlayout.html">Widgets Tutorial - Using Layouts</a>]
59
<p /><address><hr /><div align="center">
60
<table width="100%" cellspacing="0" border="0"><tr class="address">
61
<td width="40%" align="left">Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
62
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
63
<td width="40%" align="right"><div align="right">Qt 4.6.0</div></td>
64
<script type="text/javascript" src="http://www.google.com/jsapi"></script><script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script><script type="text/javascript" src="http://www.google.com/coop/cse/t13n?form=cse-search-box&t13n_langs=en"></script><script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script></tr></table></div></address></body>