msl.qt.widgets.toggle_switch module

A toggle switch QtWidgets.QWidget.

class msl.qt.widgets.toggle_switch.ToggleSwitch(*, height=None, initial=False, on_color='#009688', off_color='#B4B4B4', parent=None, toggled=None, tooltip=None)[source]

Bases: QAbstractButton

A toggle switch, toggle_switch, QtWidgets.QWidget

Parameters:
  • height (int, optional) – The height, in pixels, of the toggle switch.

  • initial (bool, optional) – Whether the toggle switch is initially in the on (True) or off (False) state.

  • on_color – The color when the ToggleSwitch is on. See to_qcolor() for details about the different data types that are supported.

  • off_color – The color when the ToggleSwitch is off. See to_qcolor() for details about the different data types that are supported.

  • parent (QtWidgets.QWidget, optional) – The parent widget.

  • toggled – A callable function to use as a slot for the toggled() signal.

  • tooltip (str, optional) – The tooltip to use for the ToggleSwitch.

Example

To view an example with the ToggleSwitch run:

>>> from msl.examples.qt import toggle_switch
>>> toggle_switch.show()  
property is_on

Whether the ToggleSwitch is on or off.

Type:

bool

off_color()[source]

Get the color of the ToggleSwitch when it is off.

Returns:

QtGui.QColor – The off color.

set_off_color(color)[source]

Set the color of the ToggleSwitch when it is off.

Parameters:

color – The color when the ToggleSwitch is off. See to_qcolor() for details about the different data types that are supported.

on_color()[source]

Get the color of the ToggleSwitch when it is on.

Returns:

QtGui.QColor – The on color.

set_on_color(color)[source]

Set the color of the ToggleSwitch when it is on.

Parameters:

color – The color when the ToggleSwitch is on. See to_qcolor() for details about the different data types that are supported.

turn_off()[source]

Turn the ToggleSwitch off.

turn_on()[source]

Turn the ToggleSwitch on.