spacr.qt.widgets.toggle

Toggle — QCheckBox styled as an iOS-style switch.

Classes

Toggle

A compact switch that can be clicked or dragged between states.

Module Contents

class spacr.qt.widgets.toggle.Toggle(text: str = '', parent=None, *, word_wrap: bool = False)[source]

Bases: PySide6.QtWidgets.QCheckBox

A compact switch that can be clicked or dragged between states.

Initialize the switch with an optional trailing label.

Parameters:
  • text – the label drawn after the switch. Empty leaves the switch alone, which is what a settings row wants – the caption beside it is the form’s, not the control’s.

  • parent – parent widget.

  • word_wrap – let a long caption wrap to the available width. False keeps the existing single-line switch layout.

heightForWidth(width: int) → int[source]

Return enough height to paint the complete wrapped caption.

Parameters:

width – available control width in logical pixels.

Returns:

wrapped height, or the native checkbox result when disabled.

minimumSizeHint() → PySide6.QtCore.QSize[source]

Allow wrapped captions to shrink without making their text a width floor.

mouseMoveEvent(event: PySide6.QtGui.QMouseEvent) → None[source]

Move the knob with the pointer while the left button is held.

Parameters:

event – the mouse move; its x position drags the knob once it is 3 pixels or more from the press.

mousePressEvent(event: PySide6.QtGui.QMouseEvent) → None[source]

Begin a click or drag without delegating a second toggle to Qt.

Parameters:

event – the mouse press; a left-button press on an enabled switch is consumed and its x position recorded, and any other press goes to the base class.

mouseReleaseEvent(event: PySide6.QtGui.QMouseEvent) → None[source]

Toggle on a tap, or select the side where a drag was released.

Parameters:

event – the mouse release; only a left-button release ending a press on this switch is handled, anything else goes to the base class.

paintEvent(event)[source]

Paint the switch track, knob, and (optional) trailing label.

Parameters:

event – the paint event; not read, since the whole switch is redrawn from its state every time.

sizeHint() → PySide6.QtCore.QSize[source]

Return the default checkbox hint widened to fit the switch track.