Skip to content

QToggleSwitch#

QToggleSwitch is a QAbstractButton subclass that represents a boolean value as a toggle switch. The API is similar to QCheckBox but with a different visual representation.

from qtpy.QtWidgets import QApplication

from superqt import QToggleSwitch

app = QApplication([])

switch = QToggleSwitch()
switch.show()

app.exec_()

QToggleSwitch

Qt Class#

QAbstractButton

Methods#

StyleOption = QStyleOptionToggleSwitch class-attribute instance-attribute #

handleColor = Property(QtGui.QColor, _get_handleColor, _set_handleColor) class-attribute instance-attribute #

Color of the switch handle.

handleSize = Property(int, _get_handleSize, _set_handleSize) class-attribute instance-attribute #

Width/height of the switch handle.

offColor = Property(QtGui.QColor, _get_offColor, _set_offColor) class-attribute instance-attribute #

Color of the switch groove when it is off.

onColor = Property(QtGui.QColor, _get_onColor, _set_onColor) class-attribute instance-attribute #

Color of the switch groove when it is on.

switchHeight = Property(int, _get_switchHeight, _set_switchHeight) class-attribute instance-attribute #

Height of the switch groove.

switchWidth = Property(int, _get_switchWidth, _set_switchWidth) class-attribute instance-attribute #

Width of the switch groove.

animationDuration() -> int #

Return the duration of the animation in milliseconds.

drawGroove(painter: QtGui.QPainter, rect: QtCore.QRectF, option: QStyleOptionToggleSwitch) -> None #

Draw the groove of the switch.

Parameters:

Name Type Description Default
painter QPainter

The painter to use for drawing.

required
rect QRectF

The rectangle in which to draw the groove.

required
option QStyleOptionToggleSwitch

The style options used for drawing.

required

drawHandle(painter: QtGui.QPainter, rect: QtCore.QRectF, option: QStyleOptionToggleSwitch) -> None #

Draw the handle of the switch.

Parameters:

Name Type Description Default
painter QPainter

The painter to use for drawing.

required
rect QRectF

The rectangle in which to draw the handle.

required
option QStyleOptionToggleSwitch

The style options used for drawing.

required

drawText(painter: QtGui.QPainter, rect: QtCore.QRectF, option: QStyleOptionToggleSwitch) -> None #

Draw the text next to the switch.

Parameters:

Name Type Description Default
painter QPainter

The painter to use for drawing.

required
rect QRectF

The rectangle in which to draw the text.

required
option QStyleOptionToggleSwitch

The style options used for drawing.

required

initStyleOption(option: QStyleOptionToggleSwitch) -> None #

Initialize the style option for the switch.

setAnimationDuration(msec: int) -> None #

Set the duration of the animation in milliseconds.

To disable animation, set duration to 0.