summaryrefslogtreecommitdiffstats
path: root/doc/src/examples/groupbox.qdoc
blob: a04243785b4daf5f93e44104eb8b71bbd23b3b90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** GNU Free Documentation License
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms
** and conditions contained in a signed written agreement between you
** and Nokia.
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
    \example widgets/groupbox
    \title Group Box Example

    The Group Box example shows how to use the different kinds of group
    boxes in Qt.

    Group boxes are container widgets that organize buttons into groups,
    both logically and on screen. They manage the interactions between
    the user and the application so that you do not have to enforce
    simple constraints.

    Group boxes are usually used to organize check boxes and radio
    buttons into exclusive groups.

    \image groupbox-example.png

    The Group Boxes example consists of a single \c Window class that
    is used to show four group boxes: an exclusive radio button group,
    a non-exclusive checkbox group, an exclusive radio button group
    with an enabling checkbox, and a group box with normal push buttons.

    \section1 Window Class Definition

    The \c Window class is a subclass of \c QWidget that is used to
    display a number of group boxes. The class definition contains
    functions to construct each group box and populate it with different
    selections of button widgets:

    \snippet examples/widgets/groupbox/window.h 0

    In the example, the widget will be used as a top-level window, so
    the constructor is defined so that we do not have to specify a parent
    widget.

    \section1 Window Class Implementation

    The constructor creates a grid layout and fills it with each of the
    group boxes that are to be displayed:

    \snippet examples/widgets/groupbox/window.cpp 0

    The functions used to create each group box each return a
    QGroupBox to be inserted into the grid layout.

    \snippet examples/widgets/groupbox/window.cpp 1

    The first group box contains and manages three radio buttons. Since
    the group box contains only radio buttons, it is exclusive by
    default, so only one radio button can be checked at any given time.
    We check the first radio button to ensure that the button group
    contains one checked button.

    \snippet examples/widgets/groupbox/window.cpp 3

    We use a vertical layout within the group box to present the
    buttons in the form of a vertical list, and return the group
    box to the constructor.

    The second group box is itself checkable, providing a convenient
    way to disable all the buttons inside it. Initially, it is
    unchecked, so the group box itself must be checked before any of
    the radio buttons inside can be checked.

    \snippet examples/widgets/groupbox/window.cpp 4

    The group box contains three exclusive radio buttons, and an
    independent checkbox. For consistency, one radio button must be
    checked at all times, so we ensure that the first one is initially
    checked.

    \snippet examples/widgets/groupbox/window.cpp 5

    The buttons are arranged in the same way as those in the first
    group box.

    \snippet examples/widgets/groupbox/window.cpp 6

    The third group box is constructed with a "flat" style that is
    better suited to certain types of dialog.

    \snippet examples/widgets/groupbox/window.cpp 7

    This group box contains only checkboxes, so it is non-exclusive by
    default. This means that each checkbox can be checked independently
    of the others.

    \snippet examples/widgets/groupbox/window.cpp 8

    Again, we use a vertical layout within the group box to present
    the buttons in the form of a vertical list.

    \snippet examples/widgets/groupbox/window.cpp 9

    The final group box contains only push buttons and, like the
    second group box, it is checkable.

    \snippet examples/widgets/groupbox/window.cpp 10

    We create a normal button, a toggle button, and a flat push button:

    \snippet examples/widgets/groupbox/window.cpp 11

    Push buttons can be used to display popup menus. We create one, and
    attach a simple menu to it:

    \snippet examples/widgets/groupbox/window.cpp 12

    Finally, we lay out the widgets vertically, and return the group box
    that we created:

    \snippet examples/widgets/groupbox/window.cpp 13
*/