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">
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/gui/widgets/qstackedwidget.cpp -->
7
<title>Qt 4.0: QStackedWidget Class Reference</title>
8
<style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
9
a:link { color: #004faf; text-decoration: none }
10
a:visited { color: #672967; text-decoration: none }
11
td.postheader { font-family: sans-serif }
12
tr.address { font-family: sans-serif }
13
body { background: #ffffff; color: black; }</style>
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
19
<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>
20
<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">QStackedWidget Class Reference</h1>
21
<p>The QStackedWidget class provides a stack of widgets where only one widget is visible at a time. <a href="#details">More...</a></p>
22
<pre>#include <QStackedWidget></pre><p>Part of the <a href="qtgui.html">QtGui</a> module.</p>
23
<p>Inherits <a href="qframe.html">QFrame</a>.</p>
25
<li><a href="qstackedwidget-members.html">List of all members, including inherited members</a></li>
27
<a name="properties"></a>
30
<li><div class="fn"/><b><a href="qstackedwidget.html#count-prop">count</a></b> : const int</li>
31
<li><div class="fn"/><b><a href="qstackedwidget.html#currentIndex-prop">currentIndex</a></b> : int</li>
34
<li><div class="fn"/>6 properties inherited from <a href="qframe.html#properties">QFrame</a></li>
35
<li><div class="fn"/>52 properties inherited from <a href="qwidget.html#properties">QWidget</a></li>
36
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
38
<a name="public-functions"></a>
39
<h3>Public Functions</h3>
41
<li><div class="fn"/><b><a href="qstackedwidget.html#QStackedWidget">QStackedWidget</a></b> ( QWidget * <i>parent</i> = 0 )</li>
42
<li><div class="fn"/><b><a href="qstackedwidget.html#dtor.QStackedWidget">~QStackedWidget</a></b> ()</li>
43
<li><div class="fn"/>int <b><a href="qstackedwidget.html#addWidget">addWidget</a></b> ( QWidget * <i>widget</i> )</li>
44
<li><div class="fn"/>int <b><a href="qstackedwidget.html#count-prop">count</a></b> () const</li>
45
<li><div class="fn"/>int <b><a href="qstackedwidget.html#currentIndex-prop">currentIndex</a></b> () const</li>
46
<li><div class="fn"/>QWidget * <b><a href="qstackedwidget.html#currentWidget">currentWidget</a></b> () const</li>
47
<li><div class="fn"/>int <b><a href="qstackedwidget.html#indexOf">indexOf</a></b> ( QWidget * <i>widget</i> ) const</li>
48
<li><div class="fn"/>int <b><a href="qstackedwidget.html#insertWidget">insertWidget</a></b> ( int <i>index</i>, QWidget * <i>widget</i> )</li>
49
<li><div class="fn"/>void <b><a href="qstackedwidget.html#removeWidget">removeWidget</a></b> ( QWidget * <i>widget</i> )</li>
50
<li><div class="fn"/>QWidget * <b><a href="qstackedwidget.html#widget">widget</a></b> ( int <i>index</i> ) const</li>
53
<li><div class="fn"/>13 public functions inherited from <a href="qframe.html#public-functions">QFrame</a></li>
54
<li><div class="fn"/>183 public functions inherited from <a href="qwidget.html#public-functions">QWidget</a></li>
55
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
56
<li><div class="fn"/>10 public functions inherited from <a href="qpaintdevice.html#public-functions">QPaintDevice</a></li>
58
<a name="public-slots"></a>
61
<li><div class="fn"/>void <b><a href="qstackedwidget.html#currentIndex-prop">setCurrentIndex</a></b> ( int <i>index</i> )</li>
62
<li><div class="fn"/>void <b><a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a></b> ( QWidget * <i>w</i> )</li>
65
<li><div class="fn"/>17 public slots inherited from <a href="qwidget.html#public-slots">QWidget</a></li>
66
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
68
<a name="signals"></a>
71
<li><div class="fn"/>void <b><a href="qstackedwidget.html#currentChanged">currentChanged</a></b> ( int <i>index</i> )</li>
72
<li><div class="fn"/>void <b><a href="qstackedwidget.html#widgetRemoved">widgetRemoved</a></b> ( int <i>index</i> )</li>
75
<li><div class="fn"/>1 signal inherited from <a href="qwidget.html#signals">QWidget</a></li>
76
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
78
<h3>Additional Inherited Members</h3>
80
<li><div class="fn"/>2 static public members inherited from <a href="qframe.html#static-public-members">QFrame</a></li>
81
<li><div class="fn"/>4 static public members inherited from <a href="qwidget.html#static-public-members">QWidget</a></li>
82
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
83
<li><div class="fn"/>39 protected functions inherited from <a href="qwidget.html#protected-functions">QWidget</a></li>
84
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
86
<a name="details"></a>
88
<h2>Detailed Description</h2>
89
<p>The QStackedWidget class provides a stack of widgets where only one widget is visible at a time.</p>
90
<p>QStackedWidget can be used to create a user interface similar to the one provided by <a href="qtabwidget.html">QTabWidget</a>. It is a convenience layout widget built on top of <a href="qstackedlayout.html">QStackedLayout</a>.</p>
91
<p>A QStackedWidget can be constructed and populated with a number of child widgets ("pages"), each of which can be created without a parent widget:</p>
92
<pre> QWidget *firstPageWidget = new QWidget;
93
QWidget *secondPageWidget = new QWidget;
94
QWidget *thirdPageWidget = new QWidget;
97
QStackedWidget *stackedWidget = new QStackedWidget(this);
98
stackedWidget->addWidget(firstPageWidget);
99
stackedWidget->addWidget(secondPageWidget);
100
stackedWidget->addWidget(thirdPageWidget);</pre>
101
<p>When inserted, the widgets are added to an internal list. The <a href="qstackedwidget.html#indexOf">indexOf</a>() function returns the index of a widget in that list. The <a href="qstackedwidget.html#widget">widget</a>() function returns the widget at a given index position. The widget that is shown on screen is the <a href="qstackedwidget.html#currentWidget">currentWidget</a>(). It can be changed using <a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a>() or <a href="qstackedwidget.html#currentIndex-prop">setCurrentIndex</a>()</p>
102
<p>QStackedWidget provides no intrinsic means for the user to switch page. This is typically done through a <a href="qcombobox.html">QComboBox</a> or a <a href="qlistwidget.html">QListWidget</a> that stores the titles of the QStackedWidget's pages. For example:</p>
103
<pre> QComboBox *pageComboBox = new QComboBox;
104
pageComboBox->addItem(tr("Page 1"));
105
pageComboBox->addItem(tr("Page 2"));
106
pageComboBox->addItem(tr("Page 3"));
107
connect(pageComboBox, SIGNAL(activated(int)),
108
stackedWidget, SLOT(setCurrentIndex(int)));</pre>
109
<p>See also <a href="qstackedlayout.html">QStackedLayout</a> and <a href="qtabwidget.html">QTabWidget</a>.</p>
111
<h2>Property Documentation</h2>
112
<h3 class="fn"><a name="count-prop"></a>count : const int</h3>
113
<p>This property holds the number of child widgets.</p>
114
<p>Access functions:</p>
116
<li><div class="fn"/><b>int count () const</b></li>
118
<p>See also <a href="qstackedwidget.html#currentIndex-prop">currentIndex</a>() and <a href="qstackedwidget.html#widget">widget</a>().</p>
119
<h3 class="fn"><a name="currentIndex-prop"></a>currentIndex : int</h3>
120
<p>This property holds the index position of the widget that is visible.</p>
121
<p>The current index is -1 if there is no current widget.</p>
122
<p>Access functions:</p>
124
<li><div class="fn"/><b>int currentIndex () const</b></li>
125
<li><div class="fn"/><b>void setCurrentIndex ( int <i>index</i> )</b></li>
127
<p>See also <a href="qstackedwidget.html#currentWidget">currentWidget</a>() and <a href="qstackedwidget.html#indexOf">indexOf</a>().</p>
129
<h2>Member Function Documentation</h2>
130
<h3 class="fn"><a name="QStackedWidget"></a>QStackedWidget::QStackedWidget ( <a href="qwidget.html">QWidget</a> * <i>parent</i> = 0 )</h3>
131
<p>Constructs a <a href="qstackedwidget.html">QStackedWidget</a> with the given <i>parent</i>.</p>
132
<h3 class="fn"><a name="dtor.QStackedWidget"></a>QStackedWidget::~QStackedWidget ()</h3>
133
<p>Destroys the object and frees any allocated resources.</p>
134
<h3 class="fn"><a name="addWidget"></a>int QStackedWidget::addWidget ( <a href="qwidget.html">QWidget</a> * <i>widget</i> )</h3>
135
<p>Adds <i>widget</i> to this <a href="qstackedwidget.html">QStackedWidget</a> and returns the index position of <i>widget</i>.</p>
136
<p>If the <a href="qstackedwidget.html">QStackedWidget</a> is empty before this function is called, <i>widget</i> becomes the current widget.</p>
137
<p>See also <a href="qstackedwidget.html#insertWidget">insertWidget</a>(), <a href="qstackedwidget.html#removeWidget">removeWidget</a>(), and <a href="qstackedwidget.html#currentWidget">currentWidget</a>().</p>
138
<h3 class="fn"><a name="currentChanged"></a>void QStackedWidget::currentChanged ( int <i>index</i> ) <tt> [signal]</tt></h3>
139
<p>This signal is emitted when the current widget is changed. The parameter holds the <i>index</i> of the new current widget, or -1 if there isn't a new one (for example, if there are no widgets in the <a href="qstackedwidget.html">QStackedWidget</a>).</p>
140
<p>See also <a href="qstackedwidget.html#widgetRemoved">widgetRemoved</a>() and <a href="qstackedwidget.html#indexOf">indexOf</a>().</p>
141
<h3 class="fn"><a name="currentWidget"></a><a href="qwidget.html">QWidget</a> * QStackedWidget::currentWidget () const</h3>
142
<p>Returns the current widget, or 0 if there are no child widgets.</p>
143
<p>Equivalent to widget(<a href="qstackedwidget.html#currentIndex-prop">currentIndex</a>()).</p>
144
<p>See also <a href="qstackedwidget.html#currentIndex-prop">currentIndex</a>() and <a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a>().</p>
145
<h3 class="fn"><a name="indexOf"></a>int QStackedWidget::indexOf ( <a href="qwidget.html">QWidget</a> * <i>widget</i> ) const</h3>
146
<p>Returns the index of <i>widget</i>, or -1 if <i>widget</i> is not a child of <a href="qstackedwidget.html">QStackedWidget</a>.</p>
147
<p>See also <a href="qstackedwidget.html#currentIndex-prop">currentIndex</a>() and <a href="qstackedwidget.html#widget">widget</a>().</p>
148
<h3 class="fn"><a name="insertWidget"></a>int QStackedWidget::insertWidget ( int <i>index</i>, <a href="qwidget.html">QWidget</a> * <i>widget</i> )</h3>
149
<p>Inserts <i>widget</i> at position <i>index</i> in this <a href="qstackedwidget.html">QStackedWidget</a>. If <i>index</i> is out of range, the widget is appended. Returns the actual index of <i>widget</i>.</p>
150
<p>If the <a href="qstackedwidget.html">QStackedWidget</a> was empty before this function is called, <i>widget</i> becomes the current widget.</p>
151
<p>See also <a href="qstackedwidget.html#addWidget">addWidget</a>(), <a href="qstackedwidget.html#removeWidget">removeWidget</a>(), <a href="qstackedwidget.html#count-prop">count</a>(), and <a href="qstackedwidget.html#currentWidget">currentWidget</a>().</p>
152
<h3 class="fn"><a name="removeWidget"></a>void QStackedWidget::removeWidget ( <a href="qwidget.html">QWidget</a> * <i>widget</i> )</h3>
153
<p>Removes <i>widget</i> from the <a href="qstackedwidget.html">QStackedWidget</a>'s layout. The widget is <i>not</i> deleted.</p>
154
<p>See also <a href="qstackedwidget.html#addWidget">addWidget</a>(), <a href="qstackedwidget.html#insertWidget">insertWidget</a>(), and <a href="qstackedwidget.html#currentWidget">currentWidget</a>().</p>
155
<h3 class="fn"><a name="setCurrentWidget"></a>void QStackedWidget::setCurrentWidget ( <a href="qwidget.html">QWidget</a> * <i>w</i> ) <tt> [slot]</tt></h3>
156
<p>Sets <i>w</i> to be the current widget. <i>w</i> must be contained in this stacked widget.</p>
158
<pre> stackedWidget->setCurrentIndex(stackedWidget->indexOf(w));</pre>
159
<p>See also <a href="qstackedwidget.html#addWidget">addWidget</a>() and <a href="qstackedwidget.html#currentIndex-prop">setCurrentIndex</a>().</p>
160
<h3 class="fn"><a name="widget"></a><a href="qwidget.html">QWidget</a> * QStackedWidget::widget ( int <i>index</i> ) const</h3>
161
<p>Returns the widget at position <i>index</i>, or 0 if there is no such widget.</p>
162
<p>See also <a href="qstackedwidget.html#indexOf">indexOf</a>().</p>
163
<h3 class="fn"><a name="widgetRemoved"></a>void QStackedWidget::widgetRemoved ( int <i>index</i> ) <tt> [signal]</tt></h3>
164
<p>This signal is emitted when the widget at position <i>index</i> is removed.</p>
165
<p>See also <a href="qstackedwidget.html#currentChanged">currentChanged</a>().</p>
166
<p /><address><hr /><div align="center">
167
<table width="100%" cellspacing="0" border="0"><tr class="address">
168
<td width="30%">Copyright © 2005 <a href="trolltech.html">Trolltech</a></td>
169
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
170
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
171
</tr></table></div></address></body>