source: trunk/doc/src/examples/groupbox.qdoc@ 5

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

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

File size: 5.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information (qt-info@nokia.com)
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 qt-sales@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/*!
43 \example widgets/groupbox
44 \title Group Box Example
45
46 The Group Box example shows how to use the different kinds of group
47 boxes in Qt.
48
49 Group boxes are container widgets that organize buttons into groups,
50 both logically and on screen. They manage the interactions between
51 the user and the application so that you do not have to enforce
52 simple constraints.
53
54 Group boxes are usually used to organize check boxes and radio
55 buttons into exclusive groups.
56
57 \image groupbox-example.png
58
59 The Group Boxes example consists of a single \c Window class that
60 is used to show four group boxes: an exclusive radio button group,
61 a non-exclusive checkbox group, an exclusive radio button group
62 with an enabling checkbox, and a group box with normal push buttons.
63
64 \section1 Window Class Definition
65
66 The \c Window class is a subclass of \c QWidget that is used to
67 display a number of group boxes. The class definition contains
68 functions to construct each group box and populate it with different
69 selections of button widgets:
70
71 \snippet examples/widgets/groupbox/window.h 0
72
73 In the example, the widget will be used as a top-level window, so
74 the constructor is defined so that we do not have to specify a parent
75 widget.
76
77 \section1 Window Class Implementation
78
79 The constructor creates a grid layout and fills it with each of the
80 group boxes that are to be displayed:
81
82 \snippet examples/widgets/groupbox/window.cpp 0
83
84 The functions used to create each group box each return a
85 QGroupBox to be inserted into the grid layout.
86
87 \snippet examples/widgets/groupbox/window.cpp 1
88
89 The first group box contains and manages three radio buttons. Since
90 the group box contains only radio buttons, it is exclusive by
91 default, so only one radio button can be checked at any given time.
92 We check the first radio button to ensure that the button group
93 contains one checked button.
94
95 \snippet examples/widgets/groupbox/window.cpp 3
96
97 We use a vertical layout within the group box to present the
98 buttons in the form of a vertical list, and return the group
99 box to the constructor.
100
101 The second group box is itself checkable, providing a convenient
102 way to disable all the buttons inside it. Initially, it is
103 unchecked, so the group box itself must be checked before any of
104 the radio buttons inside can be checked.
105
106 \snippet examples/widgets/groupbox/window.cpp 4
107
108 The group box contains three exclusive radio buttons, and an
109 independent checkbox. For consistency, one radio button must be
110 checked at all times, so we ensure that the first one is initially
111 checked.
112
113 \snippet examples/widgets/groupbox/window.cpp 5
114
115 The buttons are arranged in the same way as those in the first
116 group box.
117
118 \snippet examples/widgets/groupbox/window.cpp 6
119
120 The third group box is constructed with a "flat" style that is
121 better suited to certain types of dialog.
122
123 \snippet examples/widgets/groupbox/window.cpp 7
124
125 This group box contains only checkboxes, so it is non-exclusive by
126 default. This means that each checkbox can be checked independently
127 of the others.
128
129 \snippet examples/widgets/groupbox/window.cpp 8
130
131 Again, we use a vertical layout within the group box to present
132 the buttons in the form of a vertical list.
133
134 \snippet examples/widgets/groupbox/window.cpp 9
135
136 The final group box contains only push buttons and, like the
137 second group box, it is checkable.
138
139 \snippet examples/widgets/groupbox/window.cpp 10
140
141 We create a normal button, a toggle button, and a flat push button:
142
143 \snippet examples/widgets/groupbox/window.cpp 11
144
145 Push buttons can be used to display popup menus. We create one, and
146 attach a simple menu to it:
147
148 \snippet examples/widgets/groupbox/window.cpp 12
149
150 Finally, we lay out the widgets vertically, and return the group box
151 that we created:
152
153 \snippet examples/widgets/groupbox/window.cpp 13
154*/
Note: See TracBrowser for help on using the repository browser.