source: trunk/doc/src/tutorials/widgets-tutorial.qdoc@ 109

Last change on this file since 109 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 6.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the documentation of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/*!
43 \page widgets-tutorial.html
44
45 \title Widgets Tutorial
46 \ingroup tutorials
47
48 \brief This tutorial covers basic usage of widgets and layouts, showing how they are used to build GUI applications.
49
50 \section1 Introduction
51
52 Widgets are the basic building blocks of graphical user interface (GUI)
53 applications made with Qt. Each GUI component, such as a button, label or
54 text editor, is a widget and can be placed within an existing user
55 interface or displayed as an independent window. Each type of component
56 is provided by a particular subclass of QWidget, which is itself a
57 subclass of QObject.
58
59 QWidget is not an abstract class; it can be used as a container for other
60 widgets, and can be subclassed with minimal effort to create custom
61 widgets. It is most often used to create windows in which other widgets
62 are placed.
63
64 As with \l{QObject}s, widgets can be created with parent objects to
65 indicate ownership, ensuring that objects are deleted when they are no
66 longer used. With widgets, these parent-child relationships have an
67 additional meaning: each child is displayed within the screen area
68 occupied by its parent. This means that, when a window is deleted, all
69 the widgets it contains are automatically deleted.
70
71 \section1 Creating a Window
72
73 If a widget is created without a parent, it is treated as a window, or
74 \e{top-level widget}, when it is shown. Since it has no parent object to
75 ensure that it is deleted when no longer needed, it is up to the
76 developer to keep track of the top-level widgets in an application.
77
78 In the following example, we use QWidget to create and show a window with
79 a default size:
80
81 \raw HTML
82 <table align="left" width="100%">
83 <tr class="qt-code"><td>
84 \endraw
85 \snippet snippets/widgets-tutorial/toplevel/main.cpp create, resize and show
86 \raw HTML
87 </td><td align="right">
88 \endraw
89 \inlineimage widgets-tutorial-toplevel.png
90 \raw HTML
91 </td></tr>
92 </table>
93 \endraw
94
95 We can add a child widget to this window by passing \c window as the
96 parent to its constructor. In this case, we add a button to the window
97 and place it in a specific location:
98
99 \raw HTML
100 <table align="left" width="100%">
101 <tr class="qt-code"><td>
102 \endraw