## GtkSwitch GtkSwitch — A “light switch” style toggle |

## Functions

GtkWidget * | gtk_switch_new ()
void | gtk_switch_set_active ()
gboolean | gtk_switch_get_active ()

## Properties

gboolean | active | Read / Write

## Style Properties

gint | slider-width | Read

## Signals

void | activate | Action

## Types and Values

struct | GtkSwitch
struct | GtkSwitchClass

## Object Hierarchy

        GObject
        ╰── GInitiallyUnowned
            ╰── GtkWidget
                ╰── GtkSwitch

## Implemented Interfaces

GtkSwitch implements AtkImplementorIface, GtkBuildable, GtkActionable and GtkActivatable.

## Includes

    #include <gtk/gtk.h>

## Description

GtkSwitch is a widget that has two states: on or off. The user can control which state should be active by clicking the empty area, or by dragging the handle.

## Functions

### gtk_switch_new ()

    GtkWidget *
    gtk_switch_new (void);

Creates a new GtkSwitch widget.

#### Returns

the newly created GtkSwitch instance

Since 3.0

### gtk_switch_set_active ()

    void
    gtk_switch_set_active (GtkSwitch *sw,
                           gboolean is_active);

Changes the state of `sw` to the desired one.

#### Parameters

sw | a GtkSwitch |
is_active | `TRUE` if `sw` should be active, and `FALSE` otherwise |

Since 3.0

### gtk_switch_get_active ()

    gboolean
    gtk_switch_get_active (GtkSwitch *sw);

Gets whether the GtkSwitch is in its “on” or “off” state.

#### Parameters

sw | a GtkSwitch |

#### Returns

`TRUE` if the GtkSwitch is active, and `FALSE` otherwise

Since 3.0

## Types and Values

### struct GtkSwitch

    struct GtkSwitch;

The GtkSwitch contains private data and it should only be accessed using the provided API.

### struct GtkSwitchClass

    struct GtkSwitchClass {
      GtkWidgetClass parent_class;

      void (* activate) (GtkSwitch *sw);
    };

#### Members

GtkWidgetClass `parent_class`; | The parent class. |
`activate` () | An action signal and emitting it causes the switch to animate. |

## Property Details

### The `“active”` property

      “active”                   gboolean

Whether the GtkSwitch widget is in its on or off state.

Flags: Read / Write

Default value: FALSE

## Style Property Details

### The `“slider-width”` style property

      “slider-width”             gint

The minimum width of the GtkSwitch handle, in pixels.

Flags: Read

Allowed values: >= 36

Default value: 36

## Signal Details

### The `“activate”` signal

    void
    user_function (GtkSwitch *widget,
                   gpointer   user_data)

The ::activate signal on GtkSwitch 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.

#### Parameters

widget | the object which received the signal. |
user_data | user data set when the signal handler was connected. |

Flags: Action

## See Also

GtkToggleButton