1
<?xml version="1.0" encoding="iso-8859-1"?>
3
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6
<title>Qt 4.0: widgetgallery.cpp Example File (widgets/styles/widgetgallery.cpp)</title>
7
<style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
8
a:link { color: #004faf; text-decoration: none }
9
a:visited { color: #672967; text-decoration: none }
10
td.postheader { font-family: sans-serif }
11
tr.address { font-family: sans-serif }
12
body { background: #ffffff; color: black; }</style>
15
<table border="0" cellpadding="0" cellspacing="0" width="100%">
17
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
18
<td width="1"> </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> · <a href="annotated.html"><font color="#004faf">Annotated</font></a> · <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> · <a href="functions.html"><font color="#004faf">Functions</font></a></td>
19
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">widgetgallery.cpp Example File<br /><small><small>widgets/styles/widgetgallery.cpp</small></small></h1>
20
<pre> /****************************************************************************
22
** Copyright (C) 2005-2005 Trolltech AS. All rights reserved.
24
** This file is part of the documentation of the Qt Toolkit.
26
** This file may be distributed under the terms of the Q Public License
27
** as defined by Trolltech AS of Norway and appearing in the file
28
** LICENSE.QPL included in the packaging of this file.
30
** This file may be distributed and/or modified under the terms of the
31
** GNU General Public License version 2 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file.
35
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
36
** information about Qt Commercial License Agreements.
37
** See http://www.trolltech.com/qpl/ for QPL licensing information.
38
** See http://www.trolltech.com/gpl/ for GPL licensing information.
40
** Contact info@trolltech.com if any conditions of this licensing are
43
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
44
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
46
****************************************************************************/
48
#include <QtGui>
50
#include "norwegianwoodstyle.h"
51
#include "widgetgallery.h"
53
WidgetGallery::WidgetGallery(QWidget *parent)
56
originalPalette = QApplication::palette();
58
styleComboBox = new QComboBox;
59
styleComboBox->addItem("NorwegianWood");
60
styleComboBox->addItems(QStyleFactory::keys());
62
styleLabel = new QLabel(tr("&Style:"));
63
styleLabel->setBuddy(styleComboBox);
65
useStylePaletteCheckBox = new QCheckBox(tr("&Use style's standard palette"));
66
useStylePaletteCheckBox->setChecked(true);
68
disableWidgetsCheckBox = new QCheckBox(tr("&Disable widgets"));
70
createTopLeftGroupBox();
71
createTopRightGroupBox();
72
createBottomLeftTabWidget();
73
createBottomRightGroupBox();
76
connect(styleComboBox, SIGNAL(activated(const QString &)),
77
this, SLOT(changeStyle(const QString &)));
78
connect(useStylePaletteCheckBox, SIGNAL(toggled(bool)),
79
this, SLOT(changePalette()));
80
connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
81
topLeftGroupBox, SLOT(setDisabled(bool)));
82
connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
83
topRightGroupBox, SLOT(setDisabled(bool)));
84
connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
85
bottomLeftTabWidget, SLOT(setDisabled(bool)));
86
connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
87
bottomRightGroupBox, SLOT(setDisabled(bool)));
89
QHBoxLayout *topLayout = new QHBoxLayout;
90
topLayout->addWidget(styleLabel);
91
topLayout->addWidget(styleComboBox);
92
topLayout->addStretch(1);
93
topLayout->addWidget(useStylePaletteCheckBox);
94
topLayout->addWidget(disableWidgetsCheckBox);
96
QGridLayout *mainLayout = new QGridLayout;
97
mainLayout->addLayout(topLayout, 0, 0, 1, 2);
98
mainLayout->addWidget(topLeftGroupBox, 1, 0);
99
mainLayout->addWidget(topRightGroupBox, 1, 1);
100
mainLayout->addWidget(bottomLeftTabWidget, 2, 0);
101
mainLayout->addWidget(bottomRightGroupBox, 2, 1);
102
mainLayout->addWidget(progressBar, 3, 0, 1, 2);
103
mainLayout->setRowStretch(1, 1);
104
mainLayout->setRowStretch(2, 1);
105
mainLayout->setColumnStretch(0, 1);
106
mainLayout->setColumnStretch(1, 1);
107
setLayout(mainLayout);
109
setWindowTitle(tr("Styles"));
110
changeStyle("NorwegianWood");
113
void WidgetGallery::changeStyle(const QString &styleName)
115
if (styleName == "NorwegianWood") {
116
QApplication::setStyle(new NorwegianWoodStyle);
118
QApplication::setStyle(QStyleFactory::create(styleName));
123
void WidgetGallery::changePalette()
125
if (useStylePaletteCheckBox->isChecked())
126
QApplication::setPalette(QApplication::style()->standardPalette());
128
QApplication::setPalette(originalPalette);
131
void WidgetGallery::advanceProgressBar()
133
int curVal = progressBar->value();
134
int maxVal = progressBar->maximum();
135
progressBar->setValue(curVal + (maxVal - curVal) / 100);
138
void WidgetGallery::createTopLeftGroupBox()
140
topLeftGroupBox = new QGroupBox(tr("Group 1"));
142
radioButton1 = new QRadioButton(tr("Radio button 1"));
143
radioButton2 = new QRadioButton(tr("Radio button 2"));
144
radioButton3 = new QRadioButton(tr("Radio button 3"));
145
radioButton1->setChecked(true);
147
checkBox = new QCheckBox(tr("Tri-state check box"));
148
checkBox->setTristate(true);
149
checkBox->setCheckState(Qt::PartiallyChecked);
151
QVBoxLayout *layout = new QVBoxLayout;
152
layout->addWidget(radioButton1);
153
layout->addWidget(radioButton2);
154
layout->addWidget(radioButton3);
155
layout->addWidget(checkBox);
156
layout->addStretch(1);
157
topLeftGroupBox->setLayout(layout);
160
void WidgetGallery::createTopRightGroupBox()
162
topRightGroupBox = new QGroupBox(tr("Group 2"));
164
defaultPushButton = new QPushButton(tr("Default Push Button"));
165
defaultPushButton->setDefault(true);
167
togglePushButton = new QPushButton(tr("Toggle Push Button"));
168
togglePushButton->setCheckable(true);
169
togglePushButton->setChecked(true);
171
flatPushButton = new QPushButton(tr("Flat Push Button"));
172
flatPushButton->setFlat(true);
174
QVBoxLayout *layout = new QVBoxLayout;
175
layout->addWidget(defaultPushButton);
176
layout->addWidget(togglePushButton);
177
layout->addWidget(flatPushButton);
178
layout->addStretch(1);
179
topRightGroupBox->setLayout(layout);
182
void WidgetGallery::createBottomLeftTabWidget()
184
bottomLeftTabWidget = new QTabWidget;
185
bottomLeftTabWidget->setSizePolicy(QSizePolicy::Preferred,
186
QSizePolicy::Ignored);
188
QWidget *tab1 = new QWidget;
189
tableWidget = new QTableWidget(10, 10);
191
QHBoxLayout *tab1hbox = new QHBoxLayout;
192
tab1hbox->setMargin(5);
193
tab1hbox->addWidget(tableWidget);
194
tab1->setLayout(tab1hbox);
196
QWidget *tab2 = new QWidget;
197
textEdit = new QTextEdit;
199
textEdit->setPlainText(tr("Au clair de la lune,\n"
200
"Mon ami Pierrot,\n"
201
"Pr�te moi ta plume\n"
202
"Pour �crire un mot.\n"
203
"Ma chandelle est morte,\n"
204
"Je n'ai plus de feu.\n"
205
"Ouvre moi ta porte,\n"
206
"Pour l'amour de Dieu.\n"));
208
QHBoxLayout *tab2hbox = new QHBoxLayout;
209
tab2hbox->setMargin(5);
210
tab2hbox->addWidget(textEdit);
211
tab2->setLayout(tab2hbox);
213
bottomLeftTabWidget->addTab(tab1, tr("&Table"));
214
bottomLeftTabWidget->addTab(tab2, tr("Text &Edit"));
217
void WidgetGallery::createBottomRightGroupBox()
219
bottomRightGroupBox = new QGroupBox(tr("Group 3"));
220
bottomRightGroupBox->setCheckable(true);
221
bottomRightGroupBox->setChecked(true);
223
lineEdit = new QLineEdit("s3cRe7");
224
lineEdit->setEchoMode(QLineEdit::Password);
226
spinBox = new QSpinBox(bottomRightGroupBox);
227
spinBox->setValue(50);
229
dateTimeEdit = new QDateTimeEdit(bottomRightGroupBox);
230
dateTimeEdit->setDateTime(QDateTime::currentDateTime());
232
slider = new QSlider(Qt::Horizontal, bottomRightGroupBox);
233
slider->setValue(40);
235
scrollBar = new QScrollBar(Qt::Horizontal, bottomRightGroupBox);
236
scrollBar->setValue(60);
238
dial = new QDial(bottomRightGroupBox);
239
dial->setValue(30);
240
dial->setNotchesVisible(true);
242
QGridLayout *layout = new QGridLayout;
243
layout->addWidget(lineEdit, 0, 0, 1, 2);
244
layout->addWidget(spinBox, 1, 0, 1, 2);
245
layout->addWidget(dateTimeEdit, 2, 0, 1, 2);
246
layout->addWidget(slider, 3, 0);
247
layout->addWidget(scrollBar, 4, 0);
248
layout->addWidget(dial, 3, 1, 2, 1);
249
layout->setRowStretch(5, 1);
250
bottomRightGroupBox->setLayout(layout);
253
void WidgetGallery::createProgressBar()
255
progressBar = new QProgressBar;
256
progressBar->setRange(0, 10000);
257
progressBar->setValue(0);
259
QTimer *timer = new QTimer(this);
260
connect(timer, SIGNAL(timeout()), this, SLOT(advanceProgressBar()));
261
timer->start(1000);
263
<p /><address><hr /><div align="center">
264
<table width="100%" cellspacing="0" border="0"><tr class="address">
265
<td width="30%">Copyright © 2005 <a href="trolltech.html">Trolltech</a></td>
266
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
267
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
268
</tr></table></div></address></body>