0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 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 examples of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
#include <QtGui>
|
|
43 |
|
|
44 |
#include "window.h"
|
|
45 |
|
|
46 |
//! [0]
|
|
47 |
Window::Window(QWidget *parent)
|
|
48 |
: QWidget(parent)
|
|
49 |
{
|
|
50 |
QGridLayout *grid = new QGridLayout;
|
|
51 |
grid->addWidget(createFirstExclusiveGroup(), 0, 0);
|
|
52 |
grid->addWidget(createSecondExclusiveGroup(), 1, 0);
|
|
53 |
grid->addWidget(createNonExclusiveGroup(), 0, 1);
|
|
54 |
grid->addWidget(createPushButtonGroup(), 1, 1);
|
|
55 |
setLayout(grid);
|
|
56 |
|
|
57 |
setWindowTitle(tr("Group Boxes"));
|
|
58 |
resize(480, 320);
|
|
59 |
}
|
|
60 |
//! [0]
|
|
61 |
|
|
62 |
//! [1]
|
|
63 |
QGroupBox *Window::createFirstExclusiveGroup()
|
|
64 |
{
|
|
65 |
//! [2]
|
|
66 |
QGroupBox *groupBox = new QGroupBox(tr("Exclusive Radio Buttons"));
|
|
67 |
|
|
68 |
QRadioButton *radio1 = new QRadioButton(tr("&Radio button 1"));
|
|
69 |
QRadioButton *radio2 = new QRadioButton(tr("R&adio button 2"));
|
|
70 |
QRadioButton *radio3 = new QRadioButton(tr("Ra&dio button 3"));
|
|
71 |
|
|
72 |
radio1->setChecked(true);
|
|
73 |
//! [1] //! [3]
|
|
74 |
|
|
75 |
QVBoxLayout *vbox = new QVBoxLayout;
|
|
76 |
vbox->addWidget(radio1);
|
|
77 |
vbox->addWidget(radio2);
|
|
78 |
vbox->addWidget(radio3);
|
|
79 |
vbox->addStretch(1);
|
|
80 |
groupBox->setLayout(vbox);
|
|
81 |
//! [2]
|
|
82 |
|
|
83 |
return groupBox;
|
|
84 |
}
|
|
85 |
//! [3]
|
|
86 |
|
|
87 |
//! [4]
|
|
88 |
QGroupBox *Window::createSecondExclusiveGroup()
|
|
89 |
{
|
|
90 |
QGroupBox *groupBox = new QGroupBox(tr("E&xclusive Radio Buttons"));
|
|
91 |
groupBox->setCheckable(true);
|
|
92 |
groupBox->setChecked(false);
|
|
93 |
//! [4]
|
|
94 |
|
|
95 |
//! [5]
|
|
96 |
QRadioButton *radio1 = new QRadioButton(tr("Rad&io button 1"));
|
|
97 |
QRadioButton *radio2 = new QRadioButton(tr("Radi&o button 2"));
|
|
98 |
QRadioButton *radio3 = new QRadioButton(tr("Radio &button 3"));
|
|
99 |
radio1->setChecked(true);
|
|
100 |
QCheckBox *checkBox = new QCheckBox(tr("Ind&ependent checkbox"));
|
|
101 |
checkBox->setChecked(true);
|
|
102 |
//! [5]
|
|
103 |
|
|
104 |
//! [6]
|
|
105 |
QVBoxLayout *vbox = new QVBoxLayout;
|
|
106 |
vbox->addWidget(radio1);
|
|
107 |
vbox->addWidget(radio2);
|
|
108 |
vbox->addWidget(radio3);
|
|
109 |
vbox->addWidget(checkBox);
|
|
110 |
vbox->addStretch(1);
|
|
111 |
groupBox->setLayout(vbox);
|
|
112 |
|
|
113 |
return groupBox;
|
|
114 |
}
|
|
115 |
//! [6]
|
|
116 |
|
|
117 |
//! [7]
|
|
118 |
QGroupBox *Window::createNonExclusiveGroup()
|
|
119 |
{
|
|
120 |
QGroupBox *groupBox = new QGroupBox(tr("Non-Exclusive Checkboxes"));
|
|
121 |
groupBox->setFlat(true);
|
|
122 |
//! [7]
|
|
123 |
|
|
124 |
//! [8]
|
|
125 |
QCheckBox *checkBox1 = new QCheckBox(tr("&Checkbox 1"));
|
|
126 |
QCheckBox *checkBox2 = new QCheckBox(tr("C&heckbox 2"));
|
|
127 |
checkBox2->setChecked(true);
|
|
128 |
QCheckBox *tristateBox = new QCheckBox(tr("Tri-&state button"));
|
|
129 |
tristateBox->setTristate(true);
|
|
130 |
//! [8]
|
|
131 |
tristateBox->setCheckState(Qt::PartiallyChecked);
|
|
132 |
|
|
133 |
//! [9]
|
|
134 |
QVBoxLayout *vbox = new QVBoxLayout;
|
|
135 |
vbox->addWidget(checkBox1);
|
|
136 |
vbox->addWidget(checkBox2);
|
|
137 |
vbox->addWidget(tristateBox);
|
|
138 |
vbox->addStretch(1);
|
|
139 |
groupBox->setLayout(vbox);
|
|
140 |
|
|
141 |
return groupBox;
|
|
142 |
}
|
|
143 |
//! [9]
|
|
144 |
|
|
145 |
//! [10]
|
|
146 |
QGroupBox *Window::createPushButtonGroup()
|
|
147 |
{
|
|
148 |
QGroupBox *groupBox = new QGroupBox(tr("&Push Buttons"));
|
|
149 |
groupBox->setCheckable(true);
|
|
150 |
groupBox->setChecked(true);
|
|
151 |
//! [10]
|
|
152 |
|
|
153 |
//! [11]
|
|
154 |
QPushButton *pushButton = new QPushButton(tr("&Normal Button"));
|
|
155 |
QPushButton *toggleButton = new QPushButton(tr("&Toggle Button"));
|
|
156 |
toggleButton->setCheckable(true);
|
|
157 |
toggleButton->setChecked(true);
|
|
158 |
QPushButton *flatButton = new QPushButton(tr("&Flat Button"));
|
|
159 |
flatButton->setFlat(true);
|
|
160 |
//! [11]
|
|
161 |
|
|
162 |
//! [12]
|
|
163 |
QPushButton *popupButton = new QPushButton(tr("Pop&up Button"));
|
|
164 |
QMenu *menu = new QMenu(this);
|
|
165 |
menu->addAction(tr("&First Item"));
|
|
166 |
menu->addAction(tr("&Second Item"));
|
|
167 |
menu->addAction(tr("&Third Item"));
|
|
168 |
menu->addAction(tr("F&ourth Item"));
|
|
169 |
popupButton->setMenu(menu);
|
|
170 |
//! [12]
|
|
171 |
|
|
172 |
QAction *newAction = menu->addAction(tr("Submenu"));
|
|
173 |
QMenu *subMenu = new QMenu(tr("Popup Submenu"));
|
|
174 |
subMenu->addAction(tr("Item 1"));
|
|
175 |
subMenu->addAction(tr("Item 2"));
|
|
176 |
subMenu->addAction(tr("Item 3"));
|
|
177 |
newAction->setMenu(subMenu);
|
|
178 |
|
|
179 |
//! [13]
|
|
180 |
QVBoxLayout *vbox = new QVBoxLayout;
|
|
181 |
vbox->addWidget(pushButton);
|
|
182 |
vbox->addWidget(toggleButton);
|
|
183 |
vbox->addWidget(flatButton);
|
|
184 |
vbox->addWidget(popupButton);
|
|
185 |
vbox->addStretch(1);
|
|
186 |
groupBox->setLayout(vbox);
|
|
187 |
|
|
188 |
return groupBox;
|
|
189 |
}
|
|
190 |
//! [13]
|