Skip to content

Toggle Switch

An iOS-style toggle switch widget for boolean input.

Preview

FXToggleSwitch

FXToggleSwitch

Bases: FXThemeAware, QAbstractButton

A modern iOS/Material-style animated toggle switch.

This widget provides a sleek alternative to QCheckBox with smooth sliding animation and theme-aware colors.

Parameters:

Name Type Description Default

parent

Optional[QWidget]

Parent widget.

None

on_color

Optional[str]

Color when switch is on. If None, uses theme accent.

None

off_color

Optional[str]

Color when switch is off. If None, uses theme surface.

None

thumb_color

Optional[str]

Color of the thumb/knob. If None, uses white.

None
Signals

toggled: Emitted when the switch state changes.

Examples:

>>> switch = FXToggleSwitch()
>>> switch.toggled.connect(lambda checked: print(f"Switch: {checked}"))
>>> switch.setChecked(True)

Methods:

Name Description
hitButton

Return True if pos is inside the clickable area.

minimumSizeHint

Return the minimum size of the switch.

paintEvent

Paint the toggle switch.

position

Set the animation position and trigger repaint.

sizeHint

Return the preferred size of the switch.

hitButton

hitButton(pos)

Return True if pos is inside the clickable area.

minimumSizeHint

minimumSizeHint()

Return the minimum size of the switch.

paintEvent

paintEvent(event) -> None

Paint the toggle switch.

position

position(value: float) -> None

Set the animation position and trigger repaint.

sizeHint

sizeHint()

Return the preferred size of the switch.