Skip to content

toggle_switch

_toggle_switch

Animated toggle switch widget.

Classes:

Name Description
FXToggleSwitch

A modern iOS/Material-style animated toggle switch.

Classes

FXToggleSwitch

FXToggleSwitch(
    parent: Optional[QWidget] = None,
    on_color: Optional[str] = None,
    off_color: Optional[str] = None,
    thumb_color: Optional[str] = None,
)

Bases: FXThemeAware, QAbstractButton


              flowchart TD
              fxgui.fxwidgets._toggle_switch.FXToggleSwitch[FXToggleSwitch]
              fxgui.fxstyle.FXThemeAware[FXThemeAware]

                              fxgui.fxstyle.FXThemeAware --> fxgui.fxwidgets._toggle_switch.FXToggleSwitch
                


              click fxgui.fxwidgets._toggle_switch.FXToggleSwitch href "" "fxgui.fxwidgets._toggle_switch.FXToggleSwitch"
              click fxgui.fxstyle.FXThemeAware href "" "fxgui.fxstyle.FXThemeAware"
            

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.

Functions
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.