Skip to content

SmoothScrollBar

Qt Base Class: QScrollBar

Signature: QScrollBar(self, arg__1: PySide6.QtCore.Qt.Orientation, parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None QScrollBar(self, parent: Optional[PySide6.QtWidgets.QWidget] = None) -> None

Base classes

Name Children Inherits
ScrollBar
prettyqt.widgets.scrollbar

⋔ Inheritance diagram

graph TD
  1473367024768["custom_widgets.SmoothScrollBar"]
  1473293693120["widgets.ScrollBar"]
  1473293699952["widgets.ScrollBarMixin"]
  1473293701904["widgets.AbstractSliderMixin"]
  1473293688240["widgets.WidgetMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473245548480["gui.PaintDeviceMixin"]
  1473365414912["QtWidgets.QScrollBar"]
  1473365440288["QtWidgets.QAbstractSlider"]
  1473290849680["QtWidgets.QWidget"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473300082368["QtGui.QPaintDevice"]
  1473293693120 --> 1473367024768
  1473293699952 --> 1473293693120
  1473293701904 --> 1473293699952
  1473293688240 --> 1473293701904
  1473299815024 --> 1473293688240
  140713234304496 --> 1473299815024
  1473245548480 --> 1473293688240
  140713234304496 --> 1473245548480
  1473365414912 --> 1473293693120
  1473365440288 --> 1473365414912
  1473290849680 --> 1473365440288
  1473288842240 --> 1473290849680
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208
  1473300082368 --> 1473290849680
  1473291690208 --> 1473300082368

🛈 DocStrings

Bases: ScrollBar

Source code in prettyqt\custom_widgets\scrollbars\smoothscrollbar.py
class SmoothScrollBar(widgets.ScrollBar):
    scroll_ended = core.Signal()

    def __init__(
        self,
        orientation: constants.Orientation | constants.OrientationStr = "horizontal",
        parent: widgets.QAbstractScrollArea | None = None,
        animation_duration: int = 500,
        easing: core.easingcurve.TypeStr | core.QEasingCurve.Type = "out_cubic",
        trigger: bool = False,
    ):
        super().__init__(orientation, parent)
        self._value = self.value()
        self.widget = parent
        self._animation = core.PropertyAnimation()
        self._animation.apply_to(self.value)
        self._animation.set_easing(easing)
        self._animation.setDuration(animation_duration)
        self._animation.finished.connect(self.scroll_ended)
        self.widget.viewport().installEventFilter(self)
        if trigger:
            self.widget.h_scrollbar.valueChanged.connect(gui.Cursor.fake_mouse_move)

    def mouseMoveEvent(self, e):
        self._animation.stop()
        self._value = self.value()
        super().mouseMoveEvent(e)

    def mousePressEvent(self, e):
        self._animation.stop()
        self._value = self.value()
        super().mousePressEvent(e)

    def mouseReleaseEvent(self, e):
        self._animation.stop()
        self._value = self.value()
        super().mouseReleaseEvent(e)

    def setValue(self, value: int):
        if value == self.value():
            return
        self._animation.stop()
        self.scroll_ended.emit()
        self._animation.set_range(self.value(), value)
        self._animation.start()

    def scroll_by_value(self, value: int):
        """Scroll by given distance."""
        self._value += value
        self._value = min(max(self.minimum(), self._value), self.maximum())
        self.setValue(self._value)

    def scroll_to(self, value: int):
        """Scroll to given position."""
        self._value = value
        self._value = min(max(self.minimum(), self._value), self.maximum())
        self.setValue(self._value)

    def reset_value(self, value):
        self._value = value

    def eventFilter(self, source, event) -> bool:
        if event.type() == core.Event.Type.Wheel and source == self.widget.viewport():
            self.widget.v_scrollbar.scroll_by_value(-event.angleDelta().y())
            return True
        return False

    def set_animation_duration(self, duration: int):
        self._animation.setDuration(duration)

    def get_animation_duration(self) -> int:
        return self._animation.duration()

    def set_animation_easing(
        self,
        easing: core.easingcurve.TypeStr | core.QEasingCurve.Type = "out_cubic",
    ):
        self._animation.set_easing(easing)

    def get_animation_easing(self) -> core.easingcurve.TypeStr:
        return self._animation.get_easing()

    def animationEasing(self) -> core.QEasingCurve.Type:
        return self._animation.type()

    animation_duration = core.Property(
        int,
        set_animation_duration,
        get_animation_duration,
        doc="Duration for the animation",
    )
    animation_easing = core.Property(
        core.EasingCurve.Type,
        set_animation_easing,
        get_animation_easing,
        doc="Animation easing type",
    )

scroll_by_value(value: int)

Scroll by given distance.

Source code in prettyqt\custom_widgets\scrollbars\smoothscrollbar.py
def scroll_by_value(self, value: int):
    """Scroll by given distance."""
    self._value += value
    self._value = min(max(self.minimum(), self._value), self.maximum())
    self.setValue(self._value)

scroll_to(value: int)

Scroll to given position.

Source code in prettyqt\custom_widgets\scrollbars\smoothscrollbar.py
def scroll_to(self, value: int):
    """Scroll to given position."""
    self._value = value
    self._value = min(max(self.minimum(), self._value), self.maximum())
    self.setValue(self._value)

⌗ 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
minimum int
maximum int
singleStep int
pageStep int
value int
sliderPosition int
tracking bool
orientation Qt::Orientation
invertedAppearance bool
invertedControls bool
sliderDown bool
animation_duration int Duration for the animation
animation_easing PySide::PyObjectWrapper Animation easing type