1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the widgets module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qstackedwidget.h"
31
#include <qstackedlayout.h>
33
#include <private/qframe_p.h>
35
class QStackedWidgetPrivate : public QFramePrivate
37
Q_DECLARE_PUBLIC(QStackedWidget)
39
QStackedWidgetPrivate():layout(0){}
40
QStackedLayout *layout;
46
\brief The QStackedWidget class provides a stack of widgets where
47
only one widget is visible at a time.
50
\ingroup geomanagement
54
QStackedWidget can be used to create a user interface similar to
55
the one provided by QTabWidget. It is a convenience layout widget
56
built on top of QStackedLayout.
58
A QStackedWidget can be constructed and populated with a number
59
of child widgets ("pages"), each of which can be created without
63
QWidget *firstPageWidget = new QWidget;
64
QWidget *secondPageWidget = new QWidget;
65
QWidget *thirdPageWidget = new QWidget;
68
QStackedWidget *stackedWidget = new QStackedWidget(this);
69
stackedWidget->addWidget(firstPageWidget);
70
stackedWidget->addWidget(secondPageWidget);
71
stackedWidget->addWidget(thirdPageWidget);
74
When inserted, the widgets are added to an internal list. The
75
indexOf() function returns the index of a widget in that list.
76
The widget() function returns the widget at a given index
77
position. The widget that is shown on screen is the
78
currentWidget(). It can be changed using setCurrentWidget() or
81
QStackedWidget provides no intrinsic means for the user to switch
82
page. This is typically done through a QComboBox or a QListWidget
83
that stores the titles of the QStackedWidget's pages. For
87
QComboBox *pageComboBox = new QComboBox;
88
pageComboBox->addItem(tr("Page 1"));
89
pageComboBox->addItem(tr("Page 2"));
90
pageComboBox->addItem(tr("Page 3"));
91
connect(pageComboBox, SIGNAL(activated(int)),
92
stackedWidget, SLOT(setCurrentIndex(int)));
95
\sa QStackedLayout, QTabWidget
99
\fn void QStackedWidget::currentChanged(int index)
101
This signal is emitted when the current widget is changed. The
102
parameter holds the \a index of the new current widget, or -1 if
103
there isn't a new one (for example, if there are no widgets in
106
\sa widgetRemoved(), indexOf()
110
\fn void QStackedWidget::widgetRemoved(int index)
112
This signal is emitted when the widget at position \a index is
119
Constructs a QStackedWidget with the given \a parent.
121
QStackedWidget::QStackedWidget(QWidget *parent)
122
: QFrame(*new QStackedWidgetPrivate, parent)
125
d->layout = new QStackedLayout(this);
126
connect(d->layout, SIGNAL(widgetRemoved(int)), this, SIGNAL(widgetRemoved(int)));
127
connect(d->layout, SIGNAL(currentChanged(int)), this, SIGNAL(currentChanged(int)));
131
Destroys the object and frees any allocated resources.
133
QStackedWidget::~QStackedWidget()
138
Adds \a widget to this QStackedWidget and returns the index
139
position of \a widget.
141
If the QStackedWidget is empty before this function is called,
142
\a widget becomes the current widget.
144
\sa insertWidget(), removeWidget(), currentWidget()
146
int QStackedWidget::addWidget(QWidget *widget)
148
return d_func()->layout->addWidget(widget);
152
Inserts \a widget at position \a index in this QStackedWidget. If
153
\a index is out of range, the widget is appended. Returns the
154
actual index of \a widget.
156
If the QStackedWidget was empty before this function is called,
157
\a widget becomes the current widget.
159
\sa addWidget(), removeWidget(), count(), currentWidget()
161
int QStackedWidget::insertWidget(int index, QWidget *widget)
163
return d_func()->layout->insertWidget(index, widget);
167
Removes \a widget from the QStackedWidget's layout. The widget is
170
\sa addWidget(), insertWidget(), currentWidget()
172
void QStackedWidget::removeWidget(QWidget *widget)
174
d_func()->layout->removeWidget(widget);
178
\property QStackedWidget::currentIndex
179
\brief the index position of the widget that is visible
181
The current index is -1 if there is no current widget.
183
\sa currentWidget(), indexOf()
186
void QStackedWidget::setCurrentIndex(int index)
188
d_func()->layout->setCurrentIndex(index);
191
int QStackedWidget::currentIndex() const
193
return d_func()->layout->currentIndex();
197
Returns the current widget, or 0 if there are no child widgets.
199
Equivalent to widget(currentIndex()).
201
\sa currentIndex(), setCurrentWidget()
203
QWidget *QStackedWidget::currentWidget() const
205
return d_func()->layout->currentWidget();
211
Sets \a w to be the current widget. \a w must be contained in this
216
stackedWidget->setCurrentIndex(stackedWidget->indexOf(w));
219
\sa addWidget(), setCurrentIndex()
221
void QStackedWidget::setCurrentWidget(QWidget *w)
223
d_func()->layout->setCurrentWidget(w);
227
Returns the index of \a widget, or -1 if \a widget is not a child
230
\sa currentIndex(), widget()
232
int QStackedWidget::indexOf(QWidget *widget) const
234
return d_func()->layout->indexOf(widget);
238
Returns the widget at position \a index, or 0 if there is no such
243
QWidget *QStackedWidget::widget(int index) const
245
return d_func()->layout->widget(index);
249
\property QStackedWidget::count
250
\brief the number of child widgets
252
\sa currentIndex(), widget()
254
int QStackedWidget::count() const
256
return d_func()->layout->count();