Skip to content

Slider

Qt Base Class: QSlider

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

Base classes

Name Children Inherits
AbstractSliderMixin
prettyqt.widgets.abstractslider
QSlider
PySide6.QtWidgets
QSlider(self, orientation: PySide6.QtCore.Qt.Orientation, parent: Optional[PySide6.QtWidgets.QWidget] \= None) -> None

Subclasses

Class Module Description
SpanSlider prettyqt.custom_widgets.editors.spanslider

⋔ Inheritance diagram

graph TD
  1473296205136["widgets.Slider"]
  1473293701904["widgets.AbstractSliderMixin"]
  1473293688240["widgets.WidgetMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473245548480["gui.PaintDeviceMixin"]
  1473365411008["QtWidgets.QSlider"]
  1473365440288["QtWidgets.QAbstractSlider"]
  1473290849680["QtWidgets.QWidget"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473300082368["QtGui.QPaintDevice"]
  1473293701904 --> 1473296205136
  1473293688240 --> 1473293701904
  1473299815024 --> 1473293688240
  140713234304496 --> 1473299815024
  1473245548480 --> 1473293688240
  140713234304496 --> 1473245548480
  1473365411008 --> 1473296205136
  1473365440288 --> 1473365411008
  1473290849680 --> 1473365440288
  1473288842240 --> 1473290849680
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208
  1473300082368 --> 1473290849680
  1473291690208 --> 1473300082368

🛈 DocStrings

Bases: AbstractSliderMixin, QSlider

Vertical or horizontal slider.

Source code in prettyqt\widgets\slider.py
class Slider(widgets.AbstractSliderMixin, widgets.QSlider):
    """Vertical or horizontal slider."""

    value_changed = core.Signal(int)
    clicked = core.Signal(int)

    def __init__(self, *args, **kwargs):
        match args:
            case (str(), *rest):
                super().__init__(constants.ORIENTATION[args[0]], *rest, **kwargs)
            case _:
                super().__init__(*args, **kwargs)
        self.valueChanged.connect(self.on_value_change)
        # style = HollowHandleStyle(
        #     {
        #         "groove.height": 4,
        #         "sub-page.color": gui.QColor(72, 210, 242),
        #         "add-page.color": gui.QColor(255, 255, 255, 50),
        #         "handle.color": gui.QColor(72, 210, 242),
        #         "handle.ring-width": 2,
        #         "handle.hollow-radius": 10,
        #         "handle.margin": 0,
        #     }
        # )
        # self.setStyle(style)

    def mousePressEvent(self, e: gui.QMouseEvent):
        self.clicked.emit(self.value())
        if self.orientation() == constants.Orientation.Horizontal:
            value = e.pos().x() / self.width() * self.maximum()
        else:
            value = (self.height() - e.pos().y()) / self.height() * self.maximum()

        self.setValue(int(value))
        super().mousePressEvent(e)

    def set_tick_position(
        self, position: TickPositionAllStr | widgets.QSlider.TickPosition
    ):
        """Set the tick position for the slider.

        For vertical orientation, "above" equals to "left" and "below" to "right".

        Args:
            position: position for the ticks
        """
        if position == "left":
            position = "above"
        elif position == "right":
            position = "below"
        self.setTickPosition(TICK_POSITION.get_enum_value(position))

    def get_tick_position(self) -> TickPositionStr:
        """Return tick position.

        Returns:
            tick position
        """
        return TICK_POSITION.inverse[self.tickPosition()]

get_tick_position() -> TickPositionStr

Return tick position.

Source code in prettyqt\widgets\slider.py
def get_tick_position(self) -> TickPositionStr:
    """Return tick position.

    Returns:
        tick position
    """
    return TICK_POSITION.inverse[self.tickPosition()]

set_tick_position(position: TickPositionAllStr | widgets.QSlider.TickPosition)

Set the tick position for the slider.

For vertical orientation, "above" equals to "left" and "below" to "right".

Parameters:

Name Type Description Default
position TickPositionAllStr | TickPosition

position for the ticks

required
Source code in prettyqt\widgets\slider.py
def set_tick_position(
    self, position: TickPositionAllStr | widgets.QSlider.TickPosition
):
    """Set the tick position for the slider.

    For vertical orientation, "above" equals to "left" and "below" to "right".

    Args:
        position: position for the ticks
    """
    if position == "left":
        position = "above"
    elif position == "right":
        position = "below"
    self.setTickPosition(TICK_POSITION.get_enum_value(position))

⌗ 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
tickPosition QSlider::TickPosition
tickInterval int