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

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 5.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:FDL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
15**
16** GNU Free Documentation License
17** Alternatively, this file may be used under the terms of the GNU Free
18** Documentation License version 1.3 as published by the Free Software
19** Foundation and appearing in the file included in the packaging of this
20** file.
21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at qt-info@nokia.com.
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29 \example widgets/groupbox
30 \title Group Box Example
31
32 The Group Box example shows how to use the different kinds of group
33 boxes in Qt.
34
35 Group boxes are container widgets that organize buttons into groups,
36 both logically and on screen. They manage the interactions between
37 the user and the application so that you do not have to enforce
38 simple constraints.
39
40 Group boxes are usually used to organize check boxes and radio
41 buttons into exclusive groups.
42
43 \image groupbox-example.png
44
45 The Group Boxes example consists of a single \c Window class that
46 is used to show four group boxes: an exclusive radio button group,
47 a non-exclusive checkbox group, an exclusive radio button group
48 with an enabling checkbox, and a group box with normal push buttons.
49
50 \section1 Window Class Definition
51
52 The \c Window class is a subclass of \c QWidget that is used to
53 display a number of group boxes. The class definition contains
54 functions to construct each group box and populate it with different
55 selections of button widgets:
56
57 \snippet examples/widgets/groupbox/window.h 0
58
59 In the example, the widget will be used as a top-level window, so
60 the constructor is defined so that we do not have to specify a parent
61 widget.
62
63 \section1 Window Class Implementation
64
65 The constructor creates a grid layout and fills it with each of the
66 group boxes that are to be displayed:
67
68 \snippet examples/widgets/groupbox/window.cpp 0
69
70 The functions used to create each group box each return a
71 QGroupBox to be inserted into the grid layout.
72
73 \snippet examples/widgets/groupbox/window.cpp 1
74
75 The first group box contains and manages three radio buttons. Since
76 the group box contains only radio buttons, it is exclusive by
77 default, so only one radio button can be checked at any given time.
78 We check the first radio button to ensure that the button group
79 contains one checked button.
80
81 \snippet examples/widgets/groupbox/window.cpp 3
82
83 We use a vertical layout within the group box to present the
84 buttons in the form of a vertical list, and return the group
85 box to the constructor.
86
87 The second group box is itself checkable, providing a convenient
88 way to disable all the buttons inside it. Initially, it is
89 unchecked, so the group box itself must be checked before any of
90 the radio buttons inside can be checked.
91
92 \snippet examples/widgets/groupbox/window.cpp 4
93
94 The group box contains three exclusive radio buttons, and an
95 independent checkbox. For consistency, one radio button must be
96 checked at all times, so we ensure that the first one is initially
97 checked.
98
99 \snippet examples/widgets/groupbox/window.cpp 5
100
101 The buttons are arranged in the same way as those in the first
102 group box.
103
104 \snippet examples/widgets/groupbox/window.cpp 6
105
106 The third group box is constructed with a "flat" style that is
107 better suited to certain types of dialog.
108
109 \snippet examples/widgets/groupbox/window.cpp 7
110
111 This group box contains only checkboxes, so it is non-exclusive by
112 default. This means that each checkbox can be checked independently
113 of the others.
114
115 \snippet examples/widgets/groupbox/window.cpp 8
116
117 Again, we use a vertical layout within the group box to present
118 the buttons in the form of a vertical list.
119
120 \snippet examples/widgets/groupbox/window.cpp 9
121
122 The final group box contains only push buttons and, like the
123 second group box, it is checkable.
124
125 \snippet examples/widgets/groupbox/window.cpp 10
126
127 We create a normal button, a toggle button, and a flat push button:
128
129 \snippet examples/widgets/groupbox/window.cpp 11
130
131 Push buttons can be used to display popup menus. We create one, and
132 attach a simple menu to it:
133
134 \snippet examples/widgets/groupbox/window.cpp 12
135
136 Finally, we lay out the widgets vertically, and return the group box
137 that we created:
138
139 \snippet examples/widgets/groupbox/window.cpp 13
140*/
Note: See TracBrowser for help on using the repository browser.