Package: gtk

Class gtk:switch

Superclasses

Documented Subclasses

None

Direct Slots

active
The active property of type :boolean (Read / Write)
Whether the switch is in its on or off state.
Default value: false
state
The state property of type :boolean (Read / Write)
The backend state that is controlled by the switch. See the "state-set" signal for details.
Default value: false

Details

The gtk:switch widget is a widget that has two states: on or off.

Figure: GtkSwitch

The user can control which state should be active by clicking the switch, or by dragging the handle.

The gtk:switch widget can also handle situations where the underlying state changes with a delay. See the "state-set" signal for details.

CSS nodes

 switch
 ├── label
 ├── label
 ╰── slider    
The gtk:switch implementation has four CSS nodes, the main node with the name switch and subnodes for the slider and the on and off labels. Neither of them is using any style classes.

Accessibility

The gtk:switch implementation uses the :switch role of the gtk:accessible-role enumeration.

Signal Details

The "activate" signal
lambda (widget)    :action      
widget
The gtk:switch widget which received the signal.
The signal on the switch is an action signal and emitting it causes the switch to animate. Applications should never connect to this signal, but use the "notify::active" signal.
The "state-set" signal
lambda (widget state)    :run-last      
widget
The gtk:switch widget which received the signal.
state
The boolean with the state of the switch.
Returns
True to stop the signal emission.
The signal on the switch is emitted to change the underlying state. It is emitted when the user changes the switch position. The default handler keeps the state in sync with the active property.

To implement delayed state change, applications can connect to this signal, initiate the change of the underlying state, and call the gtk:switch-state function when the underlying state change is complete. The signal handler should return true to prevent the default handler from running.

Visually, the underlying state is represented by the trough color of the switch, while the active property is represented by the position of the switch.
 

Returned by

Slot Access Functions

Inherited Slot Access Functions

See also

2025-2-22