msl.qt.widgets.toggle_switch module

A toggle switch QtWidgets.QWidget.

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

Bases: QAbstractButton

Constructs a toggle switch, toggle_switch

Parameters:
  • parent (QtWidgets.QWidget, optional) – The parent widget.
  • height (int, optional) – The height, in pixels, of the toggle switch.
  • 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.
  • 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()  
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.
on_color()[source]

Get the color of the ToggleSwitch when it is on.

Returns:QtGui.QColor – The on 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.
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.