1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the examples of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:BSD$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** BSD License Usage |
18 | ** Alternatively, you may use this file under the terms of the BSD license |
19 | ** as follows: |
20 | ** |
21 | ** "Redistribution and use in source and binary forms, with or without |
22 | ** modification, are permitted provided that the following conditions are |
23 | ** met: |
24 | ** * Redistributions of source code must retain the above copyright |
25 | ** notice, this list of conditions and the following disclaimer. |
26 | ** * Redistributions in binary form must reproduce the above copyright |
27 | ** notice, this list of conditions and the following disclaimer in |
28 | ** the documentation and/or other materials provided with the |
29 | ** distribution. |
30 | ** * Neither the name of The Qt Company Ltd nor the names of its |
31 | ** contributors may be used to endorse or promote products derived |
32 | ** from this software without specific prior written permission. |
33 | ** |
34 | ** |
35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
46 | ** |
47 | ** $QT_END_LICENSE$ |
48 | ** |
49 | ****************************************************************************/ |
50 | |
51 | #include "window.h" |
52 | |
53 | #include <QCheckBox> |
54 | #include <QGridLayout> |
55 | #include <QGroupBox> |
56 | #include <QMenu> |
57 | #include <QPushButton> |
58 | #include <QRadioButton> |
59 | |
60 | //! [0] |
61 | Window::Window(QWidget *parent) |
62 | : QWidget(parent) |
63 | { |
64 | QGridLayout *grid = new QGridLayout; |
65 | grid->addWidget(createFirstExclusiveGroup(), row: 0, column: 0); |
66 | grid->addWidget(createSecondExclusiveGroup(), row: 1, column: 0); |
67 | grid->addWidget(createNonExclusiveGroup(), row: 0, column: 1); |
68 | grid->addWidget(createPushButtonGroup(), row: 1, column: 1); |
69 | setLayout(grid); |
70 | |
71 | setWindowTitle(tr(s: "Group Boxes" )); |
72 | resize(w: 480, h: 320); |
73 | } |
74 | //! [0] |
75 | |
76 | //! [1] |
77 | QGroupBox *Window::createFirstExclusiveGroup() |
78 | { |
79 | //! [2] |
80 | QGroupBox *groupBox = new QGroupBox(tr(s: "Exclusive Radio Buttons" )); |
81 | |
82 | QRadioButton *radio1 = new QRadioButton(tr(s: "&Radio button 1" )); |
83 | QRadioButton *radio2 = new QRadioButton(tr(s: "R&adio button 2" )); |
84 | QRadioButton *radio3 = new QRadioButton(tr(s: "Ra&dio button 3" )); |
85 | |
86 | radio1->setChecked(true); |
87 | //! [1] //! [3] |
88 | |
89 | QVBoxLayout *vbox = new QVBoxLayout; |
90 | vbox->addWidget(radio1); |
91 | vbox->addWidget(radio2); |
92 | vbox->addWidget(radio3); |
93 | vbox->addStretch(stretch: 1); |
94 | groupBox->setLayout(vbox); |
95 | //! [2] |
96 | |
97 | return groupBox; |
98 | } |
99 | //! [3] |
100 | |
101 | //! [4] |
102 | QGroupBox *Window::createSecondExclusiveGroup() |
103 | { |
104 | QGroupBox *groupBox = new QGroupBox(tr(s: "E&xclusive Radio Buttons" )); |
105 | groupBox->setCheckable(true); |
106 | groupBox->setChecked(false); |
107 | //! [4] |
108 | |
109 | //! [5] |
110 | QRadioButton *radio1 = new QRadioButton(tr(s: "Rad&io button 1" )); |
111 | QRadioButton *radio2 = new QRadioButton(tr(s: "Radi&o button 2" )); |
112 | QRadioButton *radio3 = new QRadioButton(tr(s: "Radio &button 3" )); |
113 | radio1->setChecked(true); |
114 | QCheckBox *checkBox = new QCheckBox(tr(s: "Ind&ependent checkbox" )); |
115 | checkBox->setChecked(true); |
116 | //! [5] |
117 | |
118 | //! [6] |
119 | QVBoxLayout *vbox = new QVBoxLayout; |
120 | vbox->addWidget(radio1); |
121 | vbox->addWidget(radio2); |
122 | vbox->addWidget(radio3); |
123 | vbox->addWidget(checkBox); |
124 | vbox->addStretch(stretch: 1); |
125 | groupBox->setLayout(vbox); |
126 | |
127 | return groupBox; |
128 | } |
129 | //! [6] |
130 | |
131 | //! [7] |
132 | QGroupBox *Window::createNonExclusiveGroup() |
133 | { |
134 | QGroupBox *groupBox = new QGroupBox(tr(s: "Non-Exclusive Checkboxes" )); |
135 | groupBox->setFlat(true); |
136 | //! [7] |
137 | |
138 | //! [8] |
139 | QCheckBox *checkBox1 = new QCheckBox(tr(s: "&Checkbox 1" )); |
140 | QCheckBox *checkBox2 = new QCheckBox(tr(s: "C&heckbox 2" )); |
141 | checkBox2->setChecked(true); |
142 | QCheckBox *tristateBox = new QCheckBox(tr(s: "Tri-&state button" )); |
143 | tristateBox->setTristate(true); |
144 | //! [8] |
145 | tristateBox->setCheckState(Qt::PartiallyChecked); |
146 | |
147 | //! [9] |
148 | QVBoxLayout *vbox = new QVBoxLayout; |
149 | vbox->addWidget(checkBox1); |
150 | vbox->addWidget(checkBox2); |
151 | vbox->addWidget(tristateBox); |
152 | vbox->addStretch(stretch: 1); |
153 | groupBox->setLayout(vbox); |
154 | |
155 | return groupBox; |
156 | } |
157 | //! [9] |
158 | |
159 | //! [10] |
160 | QGroupBox *Window::createPushButtonGroup() |
161 | { |
162 | QGroupBox *groupBox = new QGroupBox(tr(s: "&Push Buttons" )); |
163 | groupBox->setCheckable(true); |
164 | groupBox->setChecked(true); |
165 | //! [10] |
166 | |
167 | //! [11] |
168 | QPushButton *pushButton = new QPushButton(tr(s: "&Normal Button" )); |
169 | QPushButton *toggleButton = new QPushButton(tr(s: "&Toggle Button" )); |
170 | toggleButton->setCheckable(true); |
171 | toggleButton->setChecked(true); |
172 | QPushButton *flatButton = new QPushButton(tr(s: "&Flat Button" )); |
173 | flatButton->setFlat(true); |
174 | //! [11] |
175 | |
176 | //! [12] |
177 | QPushButton * = new QPushButton(tr(s: "Pop&up Button" )); |
178 | QMenu * = new QMenu(this); |
179 | menu->addAction(text: tr(s: "&First Item" )); |
180 | menu->addAction(text: tr(s: "&Second Item" )); |
181 | menu->addAction(text: tr(s: "&Third Item" )); |
182 | menu->addAction(text: tr(s: "F&ourth Item" )); |
183 | popupButton->setMenu(menu); |
184 | //! [12] |
185 | |
186 | QAction *newAction = menu->addAction(text: tr(s: "Submenu" )); |
187 | QMenu * = new QMenu(tr(s: "Popup Submenu" )); |
188 | subMenu->addAction(text: tr(s: "Item 1" )); |
189 | subMenu->addAction(text: tr(s: "Item 2" )); |
190 | subMenu->addAction(text: tr(s: "Item 3" )); |
191 | newAction->setMenu(subMenu); |
192 | |
193 | //! [13] |
194 | QVBoxLayout *vbox = new QVBoxLayout; |
195 | vbox->addWidget(pushButton); |
196 | vbox->addWidget(toggleButton); |
197 | vbox->addWidget(flatButton); |
198 | vbox->addWidget(popupButton); |
199 | vbox->addStretch(stretch: 1); |
200 | groupBox->setLayout(vbox); |
201 | |
202 | return groupBox; |
203 | } |
204 | //! [13] |
205 | |