CopperSpice API  1.9.1
QStackedLayout Class Reference

The QStackedLayout class provides a stack of widgets where only one widget is visible at a time. More...

Inheritance diagram for QStackedLayout:
QLayout QObject QLayoutItem

Public Types

enum  StackingMode
 
- Public Types inherited from QLayout
enum  SizeConstraint
 

Public Signals

void currentChanged (int index)
 
void widgetRemoved (int index)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

void setCurrentIndex (int index)
 
void setCurrentWidget (QWidget *widget)
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QStackedLayout ()
 
 QStackedLayout (QLayout *parentLayout)
 
 QStackedLayout (QWidget *parent)
 
 ~QStackedLayout ()
 
void addItem (QLayoutItem *item) override
 
int addWidget (QWidget *widget)
 
int count () const override
 
int currentIndex () const
 
QWidgetcurrentWidget () const
 
bool hasHeightForWidth () const override
 
int heightForWidth (int width) const override
 
int insertWidget (int index, QWidget *widget)
 
QLayoutItemitemAt (int index) const override
 
QSize minimumSize () const override
 
void setGeometry (const QRect &rect) override
 
void setStackingMode (StackingMode stackingMode)
 
QSize sizeHint () const override
 
StackingMode stackingMode () const
 
QLayoutItemtakeAt (int index) override
 
QWidgetwidget (int index) const
 
- Public Methods inherited from QLayout
 QLayout ()
 
 QLayout (QWidget *parent)
 
bool activate ()
 
void addWidget (QWidget *w)
 
QMargins contentsMargins () const
 
QRect contentsRect () const
 
QSizePolicy::ControlTypes controlTypes () const override
 
Qt::Orientations expandingDirections () const override
 
QRect geometry () const override
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
virtual int indexOf (QWidget *widget) const
 
void invalidate () override
 
bool isEmpty () const override
 
bool isEnabled () const
 
QLayout * layout () override
 
int margin () const
 
QSize maximumSize () const override
 
QWidgetmenuBar () const
 
QWidgetparentWidget () const
 
void removeItem (QLayoutItem *item)
 
void removeWidget (QWidget *widget)
 
virtual QLayoutItemreplaceWidget (QWidget *from, QWidget *to, Qt::FindChildOptions options=Qt::FindChildrenRecursively)
 
bool setAlignment (QLayout *layout, Qt::Alignment alignment)
 
void setAlignment (Qt::Alignment alignment)
 
bool setAlignment (QWidget *widget, Qt::Alignment alignment)
 
void setContentsMargins (const QMargins &margins)
 
void setContentsMargins (int left, int top, int right, int bottom)
 
void setEnabled (bool enable)
 
void setMargin (int margin)
 
void setMenuBar (QWidget *widget)
 
void setSizeConstraint (SizeConstraint constraint)
 
void setSpacing (int spacing)
 
SizeConstraint sizeConstraint () const
 
int spacing () const
 
void update ()
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 
- Public Methods inherited from QLayoutItem
 QLayoutItem (Qt::Alignment alignment=Qt::Alignment ())
 
virtual ~QLayoutItem ()
 
Qt::Alignment alignment () const
 
virtual int minimumHeightForWidth (int width) const
 
void setAlignment (Qt::Alignment alignment)
 
virtual QSpacerItemspacerItem ()
 
virtual QWidgetwidget ()
 

Properties

 count
 
 currentIndex
 
 stackingMode
 
- Properties inherited from QLayout
 margin
 
 sizeConstraint
 
 spacing
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Static Public Methods inherited from QLayout
static QSize closestAcceptableSize (const QWidget *widget, const QSize &size)
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Methods inherited from QLayout
void addChildLayout (QLayout *layout)
 
void addChildWidget (QWidget *widget)
 
QRect alignmentRect (const QRect &rect) const
 
void childEvent (QChildEvent *event) override
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

The QStackedLayout class provides a stack of widgets where only one widget is visible at a time. QStackedLayout can be used to create a user interface similar to the one provided by QTabWidget. There is also a convenience QStackedWidget class built on top of QStackedLayout.

A QStackedLayout can be populated with a number of child widgets ("pages").

QWidget *firstPageWidget = new QWidget;
QWidget *secondPageWidget = new QWidget;
QWidget *thirdPageWidget = new QWidget;
QStackedLayout *stackedLayout = new QStackedLayout;
stackedLayout->addWidget(firstPageWidget);
stackedLayout->addWidget(secondPageWidget);
stackedLayout->addWidget(thirdPageWidget);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(stackedLayout);
setLayout(mainLayout);

QStackedLayout provides no intrinsic means for the user to switch page. This is typically done through a QComboBox or a QListWidget that stores the titles of the QStackedLayout's pages.

QComboBox *pageComboBox = new QComboBox;
pageComboBox->addItem(tr("Page 1"));
pageComboBox->addItem(tr("Page 2"));
pageComboBox->addItem(tr("Page 3"));
connect(pageComboBox, SIGNAL(activated(int)), stackedLayout, SLOT(setCurrentIndex(int)));

When populating a layout, the widgets are added to an internal list. The indexOf() function returns the index of a widget in that list. The widgets can either be added to the end of the list using the addWidget() function, or inserted at a given index using the insertWidget() function. The removeWidget() function removes the widget at the given index from the layout. The number of widgets contained in the layout, can be obtained using the count() function.

The widget() function returns the widget at a given index position. The index of the widget that is shown on screen is given by currentIndex() and can be changed using setCurrentIndex(). In a similar manner, the currently shown widget can be retrieved using the currentWidget() function, and altered using the setCurrentWidget() function.

Whenever the current widget in the layout changes or a widget is removed from the layout, the currentChanged() and widgetRemoved() signals are emitted respectively.

See also
QStackedWidget, QTabWidget

Member Enumeration Documentation

This enum specifies how the layout handles its child widgets regarding their visibility.

ConstantValueDescription
QStackedLayout::StackOne0Only the current widget is visible. This is the default.
QStackedLayout::StackAll1All widgets are visible. The current widget is merely raised.

Constructor & Destructor Documentation

QStackedLayout::QStackedLayout ( )

Constructs a QStackedLayout with no parent. This QStackedLayout must be installed on a widget later on to become effective.

See also
addWidget(), insertWidget()
QStackedLayout::QStackedLayout ( QWidget parent)
explicit

Constructs a new QStackedLayout with the given parent. This layout will install itself on the parent widget and manage the geometry of its children.

QStackedLayout::QStackedLayout ( QLayout parentLayout)
explicit

Constructs a new QStackedLayout and inserts it into the given parentLayout.

QStackedLayout::~QStackedLayout ( )

Destroys this QStackedLayout. Note that the layout's widgets are not destroyed.

Method Documentation

void QStackedLayout::addItem ( QLayoutItem item)
overridevirtual

Implements QLayout::addItem()

int QStackedLayout::addWidget ( QWidget widget)

Adds the given widget to the end of this layout and returns the index position of the widget. If the QStackedLayout is empty before this function is called, the given widget becomes the current widget.

See also
insertWidget(), removeWidget(), setCurrentWidget()
int QStackedLayout::count ( ) const
overridevirtual

Must be implemented in subclasses to return the number of items in the layout.

See also
itemAt()

Implements QLayout::count()

void QStackedLayout::currentChanged ( int  index)
signal

This signal is emitted whenever the current widget in the layout changes. The index specifies the index of the new current widget, or -1 if there is not a new one (for example, if there are no widgets in the QStackedLayout)

See also
currentWidget(), setCurrentWidget()
int QStackedLayout::currentIndex ( ) const

Returns the value of the property.

QWidget * QStackedLayout::currentWidget ( ) const

Returns the current widget or nullptr if there are no widgets in this layout.

See also
currentIndex(), setCurrentWidget()
bool QStackedLayout::hasHeightForWidth ( ) const
overridevirtual

Returns true if this layout's preferred height depends on its width, otherwise returns false. The default implementation returns false. Override this method in layout managers which support height for width.

See also
heightForWidth(), QWidget::heightForWidth()

Reimplemented from QLayoutItem::hasHeightForWidth()

int QStackedLayout::heightForWidth ( int  width) const
overridevirtual

Returns the preferred height for this layout item, given the width.

The default implementation returns -1, indicating that the preferred height is independent of the width of the item. Using the method hasHeightForWidth() will typically be much faster than calling this method and testing for -1.

Override this method in layout managers which support height for width. The following example shows a typical implementation.

// m_cached_hfw should be declared mutable in MyLayout
int MyLayout::heightForWidth(int width) const
{
if (cache_dirty || cached_width != w) {
int h = calculateHeightForWidth(w);
m_cached_hfw = h;
return h;
}
return m_cached_hfw;
}

Caching is strongly recommended; without it layout will take exponential time.

See also
hasHeightForWidth()

Reimplemented from QLayoutItem::heightForWidth()

int QStackedLayout::insertWidget ( int  index,
QWidget widget 
)

Inserts the given widget at the given index in this QStackedLayout. If index is out of range, the widget is appended (in which case it is the actual index of the widget that is returned).

If the QStackedLayout is empty before this function is called, the given widget becomes the current widget.

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.

See also
addWidget(), removeWidget(), setCurrentWidget()
QLayoutItem * QStackedLayout::itemAt ( int  index) const
overridevirtual

Implements QLayout::itemAt()

QSize QStackedLayout::minimumSize ( ) const
overridevirtual

Returns the value of the property.

Reimplemented from QLayout::minimumSize()

void QStackedLayout::setCurrentIndex ( int  index)
slot

Sets the value of the property to index.

void QStackedLayout::setCurrentWidget ( QWidget widget)
slot

Sets the current widget to be the specified widget. The new current widget must already be contained in this stacked layout.

See also
setCurrentIndex(), currentWidget()
void QStackedLayout::setGeometry ( const QRect rect)
overridevirtual

Sets the value of the property to rect.

Reimplemented from QLayout::setGeometry()

void QStackedLayout::setStackingMode ( StackingMode  stackingMode)

Sets the value of the property to stackingMode.

QSize QStackedLayout::sizeHint ( ) const
overridevirtual
StackingMode QStackedLayout::stackingMode ( ) const

Returns the value of the property.

QLayoutItem * QStackedLayout::takeAt ( int  index)
overridevirtual

Implements QLayout::takeAt()

QWidget * QStackedLayout::widget ( int  index) const

Returns the widget at the given index or nullptr if there is no widget at the given position.

See also
currentWidget(), indexOf()
void QStackedLayout::widgetRemoved ( int  index)
signal

This signal is emitted whenever a widget is removed from the layout. The widget's index is passed as parameter.

See also
removeWidget()

Property Documentation

QStackedLayout::count

This property holds the number of widgets contained in the layout.

See also
currentIndex(), widget()
PropertiesClass Methods
read count
QStackedLayout::currentIndex

This property holds the index position of the widget that is visible. The current index is -1 if there is no current widget.

See also
currentWidget(), indexOf()
PropertiesClass Methods
read currentIndex
write setCurrentIndex
notify currentChanged
QStackedLayout::stackingMode

This property determines the way visibility of child widgets are handled.

The default value is StackOne. Setting the property to StackAll allows you to make use of the layout for overlay widgets that do additional drawing on top of other widgets, for example, graphical editors.

PropertiesClass Methods
read stackingMode
write setStackingMode