ToggleGroup#

Added in version 1.7.

class ToggleGroup(**properties: Any)#

Superclasses: Widget, InitiallyUnowned, Object

Implemented Interfaces: Accessible, Buildable, ConstraintTarget, Orientable

A group of exclusive toggles.

https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1-latest/toggle-group.png

AdwToggleGroup presents a set of exclusive toggles, represented as Toggle objects. Each toggle can display an icon, a label, an icon and a label, or a custom child.

Toggles are indexed by their position, with the first toggle being equivalent to 0, and so on. Use the active to get that position.

Toggles can also have optional names, set via the name property. The name of the active toggle can be accessed via the active_name property.

AdwToggle objects can be retrieved via their index or name, using get_toggle or get_toggle_by_name respectively. AdwToggleGroup also provides a SelectionModel of its toggles via the toggles property.

AdwToggleGroup is orientable, and the toggles can be displayed horizontally or vertically. This is mostly useful for icon-only toggles.

Use the homogeneous property to make the toggles take the same size, and the can_shrink to control whether the toggles can ellipsize.

Example of an AdwToggleGroup UI definition:

<object class="AdwToggleGroup">
  <property name="active-name">picture</property>
  <child>
    <object class="AdwToggle">
      <property name="icon-name">camera-photo-symbolic</property>
      <property name="tooltip" translatable="yes">Picture Mode</property>
      <property name="name">picture</property>
    </object>
  </child>
  <child>
    <object class="AdwToggle">
      <property name="icon-name">camera-video-symbolic</property>
      <property name="tooltip" translatable="yes">Recording Mode</property>
      <property name="name">recording</property>
    </object>
  </child>
</object>

See also: InlineViewSwitcher.

CSS nodes#

AdwToggleGroup has a main CSS node with the name toggle-group.

Its toggles have CSS nodes with the name toggle, and its separators have nodes with the name separator.

Toggle nodes will have a different style classes depending on their content: .text-button for labels, .image-button for icons, .image-text-button for both or no style class for custom children.

The hidden separators use the .hidden style class.

Style classes#

AdwToggleGroup can use the `.flat <style-classes.html#flat_1>`__ style class to remove its background and make it look like a group of buttons.

https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1-latest/toggle-group-flat.png

It can also use the `.round <style-classes.html#round>`__ style class to make its toggles and the group itself rounded.

https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1-latest/toggle-group-round.png

They can also be combined with each other.

https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1-latest/toggle-group-flat-round.png

Accessibility#

AdwToggleGroup uses the radio-group role. Its toggles use the radio role.

Constructors#

class ToggleGroup
classmethod new() Widget#

Creates a new AdwToggleGroup.

Added in version 1.7.

Methods#

class ToggleGroup
add(toggle: Toggle) None#

Adds a toggle to self.

Added in version 1.7.

Parameters:

toggle – the toggle to add

get_active() int#

Gets the index of the active toggle in self.

Returns INVALID_LIST_POSITION if no toggle is active.

Added in version 1.7.

get_active_name() str | None#

Gets the name of the active toggle in self.

Can be NULL if the currently active toggle doesn’t have a name.

See name.

Added in version 1.7.

get_can_shrink() bool#

Gets whether the toggles can be smaller than the natural size of their contents.

Added in version 1.7.

get_homogeneous() bool#

Gets whether all toggles take the same size.

Added in version 1.7.

get_n_toggles() int#

Gets the number of toggles within self.

Added in version 1.7.

get_toggle(index: int) Toggle | None#

Gets the toggle with index from self.

Added in version 1.7.

Parameters:

index – toggle’s index

get_toggle_by_name(name: str) Toggle | None#

Gets the toggle with the name name from self.

Added in version 1.7.

Parameters:

name – toggle name

get_toggles() SelectionModel#

Returns a ListModel that contains the toggles of the group.

This can be used to keep an up-to-date view. The model also implements SelectionModel and can be used to track and change the active toggle.

remove(toggle: Toggle) None#

Removes toggle from self.

Added in version 1.7.

Parameters:

toggle – a toggle to remove

remove_all() None#

Removes all toggles from self.

Added in version 1.7.

set_active(active: int) None#

Sets the active toggle for self.

If the index is larger than the number of toggles in self, unsets the current active toggle.

Added in version 1.7.

Parameters:

active – toggle index

set_active_name(name: str | None = None) None#

Sets the active toggle for self.

The name can be set via name.

If name is NULL, unset the current active toggle instead.

Added in version 1.7.

Parameters:

name – toggle name

set_can_shrink(can_shrink: bool) None#

Sets whether the toggles can be smaller than the natural size of their contents.

If can_shrink is TRUE, the toggle labels will ellipsize.

See can_shrink.

Added in version 1.7.

Parameters:

can_shrink – whether the toggles can shrink

set_homogeneous(homogeneous: bool) None#

Sets whether all toggles take the same size.

Added in version 1.7.

Parameters:

homogeneous – whether all toggles should take the same size

Properties#

class ToggleGroup
props.active: int#

The type of the None singleton.

Added in version 1.7.

props.active_name: str#

The type of the None singleton.

Added in version 1.7.

props.can_shrink: bool#

The type of the None singleton.

Added in version 1.7.

props.homogeneous: bool#

The type of the None singleton.

Added in version 1.7.

props.n_toggles: int#

The type of the None singleton.

Added in version 1.7.

props.toggles: SelectionModel#

The type of the None singleton.

Added in version 1.7.