File: qstackedwidget.html

package info (click to toggle)
python-qt4 4.9.3-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 34,432 kB
  • sloc: python: 34,126; cpp: 11,938; xml: 290; makefile: 223; php: 27
file content (140 lines) | stat: -rw-r--r-- 14,901 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QStackedWidget Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QStackedWidget Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1><p>The QStackedWidget class provides a stack of widgets where only
one widget is visible at a time. <a href="#details">More...</a></p>

<p>Inherits <a href="qframe.html">QFrame</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qstackedwidget.html#QStackedWidget">__init__</a></b> (<i>self</i>, QWidget&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" />int <b><a href="qstackedwidget.html#addWidget">addWidget</a></b> (<i>self</i>, QWidget&#160;<i>w</i>)</li><li><div class="fn" />int <b><a href="qstackedwidget.html#count">count</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qstackedwidget.html#currentIndex">currentIndex</a></b> (<i>self</i>)</li><li><div class="fn" />QWidget <b><a href="qstackedwidget.html#currentWidget">currentWidget</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qstackedwidget.html#event">event</a></b> (<i>self</i>, QEvent&#160;<i>e</i>)</li><li><div class="fn" />int <b><a href="qstackedwidget.html#indexOf">indexOf</a></b> (<i>self</i>, QWidget)</li><li><div class="fn" />int <b><a href="qstackedwidget.html#insertWidget">insertWidget</a></b> (<i>self</i>, int&#160;<i>index</i>, QWidget&#160;<i>w</i>)</li><li><div class="fn" /><b><a href="qstackedwidget.html#removeWidget">removeWidget</a></b> (<i>self</i>, QWidget&#160;<i>w</i>)</li><li><div class="fn" /><b><a href="qstackedwidget.html#setCurrentIndex">setCurrentIndex</a></b> (<i>self</i>, int&#160;<i>index</i>)</li><li><div class="fn" /><b><a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a></b> (<i>self</i>, QWidget&#160;<i>w</i>)</li><li><div class="fn" />QWidget <b><a href="qstackedwidget.html#widget">widget</a></b> (<i>self</i>, int)</li></ul><h3>Special Methods</h3><ul><li><div class="fn" /> <b><a href="qstackedwidget.html#__len__">__len__</a></b> (<i>self</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qstackedwidget.html#currentChanged">currentChanged</a></b> (int)</li><li><div class="fn" />void <b><a href="qstackedwidget.html#widgetRemoved">widgetRemoved</a></b> (int)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QStackedWidget class provides a stack of widgets where only
one widget is visible at a time.</p>
<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 the <a href="qstackedlayout.html">QStackedLayout</a> class.</p>
<p>Like <a href="qstackedlayout.html">QStackedLayout</a>,
QStackedWidget can be constructed and populated with a number of
child widgets ("pages"):</p>
<pre class="cpp">
     <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>firstPageWidget <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>;
     <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>secondPageWidget <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>;
     <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>thirdPageWidget <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>;

     <span class="type">QStackedWidget</span> <span class="operator">*</span>stackedWidget <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QStackedWidget</span>;
     stackedWidget<span class="operator">-</span><span class="operator">&gt;</span>addWidget(firstPageWidget);
     stackedWidget<span class="operator">-</span><span class="operator">&gt;</span>addWidget(secondPageWidget);
     stackedWidget<span class="operator">-</span><span class="operator">&gt;</span>addWidget(thirdPageWidget);

     <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>;
     layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(stackedWidget);
     setLayout(layout);
</pre>
<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>
<pre class="cpp">
     <span class="type"><a href="qcombobox.html">QComboBox</a></span> <span class="operator">*</span>pageComboBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
     pageComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">"Page 1"</span>));
     pageComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">"Page 2"</span>));
     pageComboBox<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">"Page 3"</span>));
     connect(pageComboBox<span class="operator">,</span> SIGNAL(activated(<span class="type">int</span>))<span class="operator">,</span>
             stackedWidget<span class="operator">,</span> SLOT(setCurrentIndex(<span class="type">int</span>)));
</pre>
<p>When populating a stacked widget, 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 widgets can either be added to
the end of the list using the <a href="qstackedwidget.html#addWidget">addWidget</a>() function, or
inserted at a given index using the <a href="qstackedwidget.html#insertWidget">insertWidget</a>() function. The
<a href="qstackedwidget.html#removeWidget">removeWidget</a>()
function removes a widget from the stacked widget. The number of
widgets contained in the stacked widget, can be obtained using the
<a href="qstackedwidget.html#count-prop">count</a>() function.</p>
<p>The <a href="qstackedwidget.html#widget">widget</a>() function
returns the widget at a given index position. The index of the
widget that is shown on screen is given by <a href="qstackedwidget.html#currentIndex-prop">currentIndex</a>() and can
be changed using <a href="qstackedwidget.html#currentIndex-prop">setCurrentIndex</a>(). In a
similar manner, the currently shown widget can be retrieved using
the <a href="qstackedwidget.html#currentWidget">currentWidget</a>()
function, and altered using the <a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a>()
function.</p>
<p>Whenever the current widget in the stacked widget changes or a
widget is removed from the stacked widget, the <a href="qstackedwidget.html#currentChanged">currentChanged</a>() and
<a href="qstackedwidget.html#widgetRemoved">widgetRemoved</a>()
signals are emitted respectively.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QStackedWidget" />QStackedWidget.__init__ (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>parent</i>&#160;=&#160;None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qstackedwidget.html">QStackedWidget</a>
with the given <i>parent</i>.</p>
<p><b>See also</b> <a href="qstackedwidget.html#addWidget">addWidget</a>() and <a href="qstackedwidget.html#insertWidget">insertWidget</a>().</p>


<h3 class="fn"><a name="addWidget" />int QStackedWidget.addWidget (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>w</i>)</h3><p>The <i>w</i> argument has it's ownership transferred to Qt.</p><p>Appends the given <i>widget</i> to the <a href="qstackedwidget.html">QStackedWidget</a> and returns the index
position. Ownership of <i>widget</i> is passed on to the <a href="qstackedwidget.html">QStackedWidget</a>.</p>
<p>If the <a href="qstackedwidget.html">QStackedWidget</a> is empty
before this function is called, <i>widget</i> becomes the current
widget.</p>
<p><b>See also</b> <a href="qstackedwidget.html#insertWidget">insertWidget</a>(), <a href="qstackedwidget.html#removeWidget">removeWidget</a>(), and <a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a>().</p>


<h3 class="fn"><a name="count" />int QStackedWidget.count (<i>self</i>)</h3><h3 class="fn"><a name="currentIndex" />int QStackedWidget.currentIndex (<i>self</i>)</h3><h3 class="fn"><a name="currentWidget" /><a href="qwidget.html">QWidget</a> QStackedWidget.currentWidget (<i>self</i>)</h3><p>Returns the current widget, or 0 if there are no child
widgets.</p>
<p><b>See also</b> <a href="qstackedwidget.html#currentIndex-prop">currentIndex</a>() and
<a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a>().</p>


<h3 class="fn"><a name="event" />bool QStackedWidget.event (<i>self</i>, <a href="qevent.html">QEvent</a>&#160;<i>e</i>)</h3><p>Reimplemented from <a href="qobject.html#event">QObject.event</a>().</p>


<h3 class="fn"><a name="indexOf" />int QStackedWidget.indexOf (<i>self</i>, <a href="qwidget.html">QWidget</a>)</h3><p>Returns the index of the given <i>widget</i>, or -1 if the given
<i>widget</i> is not a child of the <a href="qstackedwidget.html">QStackedWidget</a>.</p>
<p><b>See also</b> <a href="qstackedwidget.html#currentIndex-prop">currentIndex</a>() and
<a href="qstackedwidget.html#widget">widget</a>().</p>


<h3 class="fn"><a name="insertWidget" />int QStackedWidget.insertWidget (<i>self</i>, int&#160;<i>index</i>, <a href="qwidget.html">QWidget</a>&#160;<i>w</i>)</h3><p>The <i>w</i> argument has it's ownership transferred to Qt.</p><p>Inserts the given <i>widget</i> at the given <i>index</i> in the
<a href="qstackedwidget.html">QStackedWidget</a>. Ownership of
<i>widget</i> is passed on to the <a href="qstackedwidget.html">QStackedWidget</a>. If <i>index</i> is out of
range, the <i>widget</i> is appended (in which case it is the
actual index of the <i>widget</i> that is returned).</p>
<p>If the <a href="qstackedwidget.html">QStackedWidget</a> was
empty before this function is called, the given <i>widget</i>
becomes the current widget.</p>
<p>Inserting a new widget at an index less than or equal to the
current index will increment the current index, but keep the
current widget.</p>
<p><b>See also</b> <a href="qstackedwidget.html#addWidget">addWidget</a>(), <a href="qstackedwidget.html#removeWidget">removeWidget</a>(), and <a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a>().</p>


<h3 class="fn"><a name="removeWidget" />QStackedWidget.removeWidget (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>w</i>)</h3><p>Removes <i>widget</i> from the <a href="qstackedwidget.html">QStackedWidget</a>. i.e., <i>widget</i> is
<i>not</i> deleted but simply removed from the stacked layout,
causing it to be hidden.</p>
<p><b>Note:</b> Ownership of <i>widget</i> reverts to the
application.</p>
<p><b>See also</b> <a href="qstackedwidget.html#addWidget">addWidget</a>(), <a href="qstackedwidget.html#insertWidget">insertWidget</a>(), and <a href="qstackedwidget.html#currentWidget">currentWidget</a>().</p>


<h3 class="fn"><a name="setCurrentIndex" />QStackedWidget.setCurrentIndex (<i>self</i>, int&#160;<i>index</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void setCurrentIndex(int)</tt>.</p><h3 class="fn"><a name="setCurrentWidget" />QStackedWidget.setCurrentWidget (<i>self</i>, <a href="qwidget.html">QWidget</a>&#160;<i>w</i>)</h3><p>This method is also a Qt slot with the C++ signature <tt>void setCurrentWidget(QWidget *)</tt>.</p><p>Sets the current widget to be the specified <i>widget</i>. The
new current widget must already be contained in this stacked
widget.</p>
<p><b>See also</b> <a href="qstackedwidget.html#currentWidget">currentWidget</a>() and
<a href="qstackedwidget.html#currentIndex-prop">setCurrentIndex</a>().</p>


<h3 class="fn"><a name="widget" /><a href="qwidget.html">QWidget</a> QStackedWidget.widget (<i>self</i>, int)</h3><p>Returns the widget at the given <i>index</i>, or 0 if there is
no such widget.</p>
<p><b>See also</b> <a href="qstackedwidget.html#currentWidget">currentWidget</a>() and
<a href="qstackedwidget.html#indexOf">indexOf</a>().</p>


<h3 class="fn"><a name="__len__" /> QStackedWidget.__len__ (<i>self</i>)</h3><hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="currentChanged" />void currentChanged (int)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever the current widget changes.</p>
<p>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>
<p><b>See also</b> <a href="qstackedwidget.html#currentWidget">currentWidget</a>() and
<a href="qstackedwidget.html#setCurrentWidget">setCurrentWidget</a>().</p>


<h3 class="fn"><a name="widgetRemoved" />void widgetRemoved (int)</h3><p>This is the default overload of this signal.</p><p>This signal is emitted whenever a widget is removed. The
widget's <i>index</i> is passed as parameter.</p>
<p><b>See also</b> <a href="qstackedwidget.html#removeWidget">removeWidget</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;4.9.3 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.2</td></tr></table></div></address></body></html>