Skip to content

StackedWidget

Qt Base Class: QStackedWidget

Signature: QStackedWidget(self, parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None

Base classes

Name Children Inherits
FrameMixin
prettyqt.widgets.frame
QStackedWidget
PySide6.QtWidgets
QStackedWidget(self, parent: Optional[PySide6.QtWidgets.QWidget] \= None) -> None

⋔ Inheritance diagram

graph TD
  1473296387648["widgets.StackedWidget"]
  1473293662864["widgets.FrameMixin"]
  1473293688240["widgets.WidgetMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473245548480["gui.PaintDeviceMixin"]
  1473290628128["QtWidgets.QStackedWidget"]
  1473290626176["QtWidgets.QFrame"]
  1473290849680["QtWidgets.QWidget"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473300082368["QtGui.QPaintDevice"]
  1473293662864 --> 1473296387648
  1473293688240 --> 1473293662864
  1473299815024 --> 1473293688240
  140713234304496 --> 1473299815024
  1473245548480 --> 1473293688240
  140713234304496 --> 1473245548480
  1473290628128 --> 1473296387648
  1473290626176 --> 1473290628128
  1473290849680 --> 1473290626176
  1473288842240 --> 1473290849680
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208
  1473300082368 --> 1473290849680
  1473291690208 --> 1473300082368

🛈 DocStrings

Bases: FrameMixin, QStackedWidget

Widget containing stack of widgets where only one widget is visible at a time.

Source code in prettyqt\widgets\stackedwidget.py
class StackedWidget(widgets.FrameMixin, widgets.QStackedWidget):
    """Widget containing stack of widgets where only one widget is visible at a time."""

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.animator = animations.Animator(self)

    def __add__(self, other: widgets.QWidget) -> StackedWidget:
        self.addWidget(other)
        return self

    @overload
    def __getitem__(self, index: int) -> widgets.QWidget:
        ...

    @overload
    def __getitem__(self, index: slice) -> listdelegators.ListDelegator[widgets.QWidget]:
        ...

    def __getitem__(
        self, index: int | slice
    ) -> widgets.QWidget | listdelegators.ListDelegator[widgets.QWidget]:
        match index:
            case int():
                if index >= self.count():
                    raise IndexError(index)
                return self.widget(index)
            case slice():
                rng = range(index.start or 0, index.stop or self.count(), index.step or 1)
                return listdelegators.ListDelegator(self.widget(i) for i in rng)
            case _:
                raise TypeError(index)

    def __delitem__(self, item: int | widgets.QWidget):
        if isinstance(item, int):
            item = self.widget(item)
        self.removeWidget(item)

    def __len__(self):
        # needed for PySide6
        return self.count()

    def __contains__(self, item: widgets.QWidget):
        return self.indexOf(item) >= 0

⌗ Property table

Qt Property Type Doc
objectName QString
modal bool
windowModality Qt::WindowModality
enabled bool
geometry QRect
frameGeometry QRect
normalGeometry QRect
x int
y int
pos QPoint
frameSize QSize
size QSize
width int
height int
rect QRect
childrenRect QRect
childrenRegion QRegion
sizePolicy QSizePolicy
minimumSize QSize
maximumSize QSize
minimumWidth int
minimumHeight int
maximumWidth int
maximumHeight int
sizeIncrement QSize
baseSize QSize
palette QPalette
font QFont
cursor QCursor
mouseTracking bool
tabletTracking bool
isActiveWindow bool
focusPolicy Qt::FocusPolicy
focus bool
contextMenuPolicy Qt::ContextMenuPolicy
updatesEnabled bool
visible bool
minimized bool
maximized bool
fullScreen bool
sizeHint QSize
minimumSizeHint QSize
acceptDrops bool
windowTitle QString
windowIcon QIcon
windowIconText QString
windowOpacity double
windowModified bool
toolTip QString
toolTipDuration int
statusTip QString
whatsThis QString
accessibleName QString
accessibleDescription QString
layoutDirection Qt::LayoutDirection
autoFillBackground bool
styleSheet QString
locale QLocale
windowFilePath QString
inputMethodHints QFlags
frameShape QFrame::Shape
frameShadow QFrame::Shadow
lineWidth int
midLineWidth int
frameWidth int
frameRect QRect
currentIndex int
count int