Switches

A switch is a UI control that has two states, On and Off.

The switch widget state is tracked by the GtkSwitch:active property.

Labelling a switch

A section outlining some functionality

GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);

GtkWidget *label = gtk_label_new ("Enable awesomeness");
GtkWidget *sw = gtk_switch_new ();

gtk_box_append (GTK_BOX (box), label);
gtk_box_append (GTK_BOX (box), sw);

// The switch__notify_active() function is defined elsewhere
g_signal_connect (sw, "notify::active",
                  G_CALLBACK (switch__notify_active),
                  NULL);

Useful methods for the component

  • Labels with mnemonics should call set_mnemonic_widget() to activate the switch; see the tutorial for the Label component.

  • The GtkSwitch::state-set signal can be used to control the state of the switch before the GtkSwitch:active property is changed.

API references

In the examples we used the following classes: