Skip to content

ScrollArea

Qt Base Class: QScrollArea

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

Base classes

Name Children Inherits
AbstractScrollAreaMixin
prettyqt.widgets.abstractscrollarea
QScrollArea
PySide6.QtWidgets
QScrollArea(self, parent: Optional[PySide6.QtWidgets.QWidget] \= None) -> None

⋔ Inheritance diagram

graph TD
  1473293700928["widgets.ScrollArea"]
  1473293679456["widgets.AbstractScrollAreaMixin"]
  1473293662864["widgets.FrameMixin"]
  1473293688240["widgets.WidgetMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473245548480["gui.PaintDeviceMixin"]
  1473290656432["QtWidgets.QScrollArea"]
  1473290616416["QtWidgets.QAbstractScrollArea"]
  1473290626176["QtWidgets.QFrame"]
  1473290849680["QtWidgets.QWidget"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473300082368["QtGui.QPaintDevice"]
  1473293679456 --> 1473293700928
  1473293662864 --> 1473293679456
  1473293688240 --> 1473293662864
  1473299815024 --> 1473293688240
  140713234304496 --> 1473299815024
  1473245548480 --> 1473293688240
  140713234304496 --> 1473245548480
  1473290656432 --> 1473293700928
  1473290616416 --> 1473290656432
  1473290626176 --> 1473290616416
  1473290849680 --> 1473290626176
  1473288842240 --> 1473290849680
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208
  1473300082368 --> 1473290849680
  1473291690208 --> 1473300082368

🛈 DocStrings

Bases: AbstractScrollAreaMixin, QScrollArea

Scrolling view onto another widget.

Source code in prettyqt\widgets\scrollarea.py
class ScrollArea(widgets.AbstractScrollAreaMixin, widgets.QScrollArea):
    """Scrolling view onto another widget."""

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        viewport = widgets.Widget(self, object_name=f"{type(self).__name__}_viewport")
        self.setViewport(viewport)

    def __add__(self, other: widgets.QWidget | widgets.QLayout | list):
        self.add(other)
        return self

    def get_visible_widgets(
        self,
        typ: type[T] = widgets.QWidget,
        partial_allowed: bool = True,
        margin: int = 10,
        recursive: bool = True,
    ) -> listdelegators.ListDelegator[T]:
        """Return all widgets which are visible in the viewport.

        Results can be filtered by type and whether widget is fully or partially visible.
        A positive margin increases the area to search for widgets, a negative margin
        decreases it.
        """
        widget = self.widget()
        viewport = self.viewport()
        rect = viewport.rect().adjusted(-margin, -margin, margin, margin)
        found = []
        for w in widget.find_children(typ, recursive=recursive):
            top_left = w.mapTo(viewport, w.rect().topLeft())
            bottom_right = w.mapTo(viewport, w.rect().bottomRight())
            mapped = core.Rect(top_left, bottom_right)
            if partial_allowed and rect.intersects(mapped):
                found.append(w)
            elif not partial_allowed and rect.contains(mapped):
                found.append(w)
        return listdelegators.ListDelegator(found)

    def get_children(self) -> listdelegators.ListDelegator[widgets.QWidget]:
        return self.widget().layout().get_children()

    def set_widget(self, widget: widgets.QWidget):
        self.setWidget(widget)

    def add_widget(self, *args, **kwargs):
        self.widget().layout().addWidget(*args, **kwargs)

    def add_layout(self, *args, **kwargs):
        self.widget().layout().addLayout(*args, **kwargs)

    def add(
        self,
        item: widgets.QWidget | widgets.QLayout | list,
        stretch: float | None = None,
    ):
        match item:
            case widgets.QWidget():
                self.add_widget(item)
                if stretch:
                    self.widget().layout().setStretchFactor(self.count() - 1, stretch)
            case widgets.QLayout():
                widget = widgets.Widget(self)
                widget.set_layout(item)
                self.add_widget(widget)
                if stretch:
                    self.setStretchFactor(self.count() - 1, stretch)
            case list():
                for i in item:
                    self.add(i, stretch)
        return item

get_visible_widgets(typ: type[T] = widgets.QWidget, partial_allowed: bool = True, margin: int = 10, recursive: bool = True) -> listdelegators.ListDelegator[T]

Return all widgets which are visible in the viewport.

Results can be filtered by type and whether widget is fully or partially visible. A positive margin increases the area to search for widgets, a negative margin decreases it.

Source code in prettyqt\widgets\scrollarea.py
def get_visible_widgets(
    self,
    typ: type[T] = widgets.QWidget,
    partial_allowed: bool = True,
    margin: int = 10,
    recursive: bool = True,
) -> listdelegators.ListDelegator[T]:
    """Return all widgets which are visible in the viewport.

    Results can be filtered by type and whether widget is fully or partially visible.
    A positive margin increases the area to search for widgets, a negative margin
    decreases it.
    """
    widget = self.widget()
    viewport = self.viewport()
    rect = viewport.rect().adjusted(-margin, -margin, margin, margin)
    found = []
    for w in widget.find_children(typ, recursive=recursive):
        top_left = w.mapTo(viewport, w.rect().topLeft())
        bottom_right = w.mapTo(viewport, w.rect().bottomRight())
        mapped = core.Rect(top_left, bottom_right)
        if partial_allowed and rect.intersects(mapped):
            found.append(w)
        elif not partial_allowed and rect.contains(mapped):
            found.append(w)
    return listdelegators.ListDelegator(found)

⌗ 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
verticalScrollBarPolicy Qt::ScrollBarPolicy
horizontalScrollBarPolicy Qt::ScrollBarPolicy
sizeAdjustPolicy QAbstractScrollArea::SizeAdjustPolicy
widgetResizable bool
alignment QFlags