Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qstackedwidget.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qstackedwidget.h"
5
6#include <qstackedlayout.h>
7#include <qevent.h>
8#include <private/qframe_p.h>
9
11
13{
14 Q_DECLARE_PUBLIC(QStackedWidget)
15public:
18};
19
98{
99 Q_D(QStackedWidget);
100 d->layout = new QStackedLayout(this);
101 connect(d->layout, SIGNAL(widgetRemoved(int)), this, SIGNAL(widgetRemoved(int)));
102 connect(d->layout, SIGNAL(currentChanged(int)), this, SIGNAL(currentChanged(int)));
103}
104
109{
110}
111
123{
124 return d_func()->layout->addWidget(widget);
125}
126
143{
144 return d_func()->layout->insertWidget(index, widget);
145}
146
159{
160 d_func()->layout->removeWidget(widget);
161}
162
176{
177 d_func()->layout->setCurrentIndex(index);
178}
179
181{
182 return d_func()->layout->currentIndex();
183}
184
191{
192 return d_func()->layout->currentWidget();
193}
194
195
205{
206 Q_D(QStackedWidget);
207 if (Q_UNLIKELY(d->layout->indexOf(widget) == -1)) {
208 qWarning("QStackedWidget::setCurrentWidget: widget %p not contained in stack", widget);
209 return;
210 }
211 d->layout->setCurrentWidget(widget);
212}
213
221{
222 return d_func()->layout->indexOf(widget);
223}
224
232{
233 return d_func()->layout->widget(index);
234}
235
245{
246 return d_func()->layout->count();
247}
248
251{
252 return QFrame::event(e);
253}
254
256
257#include "moc_qstackedwidget.cpp"
\inmodule QtCore
Definition qcoreevent.h:45
The QFrame class is the base class of widgets that can have a frame.
Definition qframe.h:17
bool event(QEvent *e) override
\reimp
Definition qframe.cpp:511
virtual QWidget * widget() const
If this item manages a QWidget, returns that widget.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
The QStackedLayout class provides a stack of widgets where only one widget is visible at a time.
QStackedLayout * layout
The QStackedWidget class provides a stack of widgets where only one widget is visible at a time.
void widgetRemoved(int index)
This signal is emitted whenever a widget is removed.
void setCurrentWidget(QWidget *w)
Sets the current widget to be the specified widget.
QWidget * currentWidget() const
Returns the current widget, or \nullptr if there are no child widgets.
void setCurrentIndex(int index)
bool event(QEvent *e) override
\reimp
~QStackedWidget()
Destroys this stacked widget, and frees any allocated resources.
int insertWidget(int index, QWidget *w)
Inserts the given widget at the given index in the QStackedWidget.
int indexOf(const QWidget *) const
Returns the index of the given widget, or -1 if the given widget is not a child of the QStackedWidget...
int addWidget(QWidget *w)
Appends the given widget to the QStackedWidget and returns the index position.
void removeWidget(QWidget *w)
Removes widget from the QStackedWidget.
void currentChanged(int)
This signal is emitted whenever the current widget changes.
int currentIndex
the index position of the widget that is visible
int count
the number of widgets contained by this stacked widget
QStackedWidget(QWidget *parent=nullptr)
Constructs a QStackedWidget with the given parent.
QWidget * widget(int) const
Returns the widget at the given index, or \nullptr if there is no such widget.
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QLayout * layout() const
Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is inst...
QOpenGLWidget * widget
[1]
double e
Combined button and popup list for selecting options.
#define Q_UNLIKELY(x)
#define qWarning
Definition qlogging.h:162
#define SIGNAL(a)
Definition qobjectdefs.h:52
GLuint index
[2]
QObject::connect nullptr
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent