Adw.ButtonContent

g Adw.ButtonContent Adw.ButtonContent GObject.GInterface GObject.GInterface Gtk.Accessible Gtk.Accessible GObject.GInterface->Gtk.Accessible Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.ConstraintTarget Gtk.ConstraintTarget GObject.GInterface->Gtk.ConstraintTarget GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.Widget Gtk.Widget GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Accessible->Gtk.Widget Gtk.Buildable->Gtk.Widget Gtk.ConstraintTarget->Gtk.Widget Gtk.Widget->Adw.ButtonContent

Subclasses:

None

Methods

Inherited:

Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1)

Structs:

Gtk.WidgetClass (18), GObject.ObjectClass (5)

class

new ()

get_can_shrink ()

get_icon_name ()

get_label ()

get_use_underline ()

set_can_shrink (can_shrink)

set_icon_name (icon_name)

set_label (label)

set_use_underline (use_underline)

Virtual Methods

Inherited:

Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)

Properties

Inherited:

Gtk.Widget (34), Gtk.Accessible (1)

Name

Type

Flags

Short Description

can-shrink

bool

r/w/en

icon-name

str

r/w/en

label

str

r/w/en

use-underline

bool

r/w/en

Signals

Inherited:

Gtk.Widget (13), GObject.Object (1)

Fields

Inherited:

Gtk.Widget (13), GObject.Object (1)

Class Details

class Adw.ButtonContent(**kwargs)
Bases:

Gtk.Widget

Abstract:

No

Structure:

Adw.ButtonContentClass

A helper widget for creating buttons.

<picture> <source srcset=”button-content-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”button-content.png” alt=”button-content”> </picture>

AdwButtonContent is a box-like widget with an icon and a label.

It’s intended to be used as a direct child of [class`Gtk`.Button], [class`Gtk`.MenuButton] or [class`SplitButton`], when they need to have both an icon and a label, as follows:

``xml <object class=”GtkButton”>

<property name=”child”>
<object class=”AdwButtonContent”>

<property name=”icon-name”>document-open-symbolic</property> <property name=”label” translatable=”yes”>_Open</property> <property name=”use-underline”>True</property>

</object>

</property>

</object> ``

AdwButtonContent handles style classes and connecting the mnemonic to the button automatically.

CSS nodes

`` buttoncontent ╰── box

├── image ╰── label

``

AdwButtonContent’s CSS node is called buttoncontent. It contains a box subnode that serves as a container for the image and label nodes.

When inside a GtkButton or AdwSplitButton, the button will receive the .image-text-button style class. When inside a GtkMenuButton, the internal GtkButton will receive it instead.

Accessibility

AdwButtonContent uses the GTK_ACCESSIBLE_ROLE_GROUP role.

classmethod new()
Returns:

the new created AdwButtonContent

Return type:

Gtk.Widget

Creates a new AdwButtonContent.

get_can_shrink()
Returns:

whether the button can shrink

Return type:

bool

gets whether the button can be smaller than the natural size of its contents.

New in version 1.4.

get_icon_name()
Returns:

the icon name

Return type:

str

Gets the name of the displayed icon.

get_label()
Returns:

the label

Return type:

str

Gets the displayed label.

get_use_underline()
Returns:

whether an underline in the text indicates a mnemonic

Return type:

bool

Gets whether an underline in the text indicates a mnemonic.

set_can_shrink(can_shrink)
Parameters:

can_shrink (bool) – whether the button can shrink

Sets whether the button can be smaller than the natural size of its contents.

If set to TRUE, the label will ellipsize.

See [method`Gtk`.Button.set_can_shrink].

New in version 1.4.

set_icon_name(icon_name)
Parameters:

icon_name (str) – the new icon name

Sets the name of the displayed icon.

If empty, the icon is not shown.

set_label(label)
Parameters:

label (str) – the new label

Sets the displayed label.

set_use_underline(use_underline)
Parameters:

use_underline (bool) – whether an underline in the text indicates a mnemonic

Sets whether an underline in the text indicates a mnemonic.

The mnemonic can be used to activate the parent button.

See [property`ButtonContent`:py:data::label<Adw.ButtonContent.props.label>].

Property Details

Adw.ButtonContent.props.can_shrink
Name:

can-shrink

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether the button can be smaller than the natural size of its contents.

If set to TRUE, the label will ellipsize.

See [property`Gtk`.Button:can-shrink].

New in version 1.4.

Adw.ButtonContent.props.icon_name
Name:

icon-name

Type:

str

Default Value:

''

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The name of the displayed icon.

If empty, the icon is not shown.

Adw.ButtonContent.props.label
Name:

label

Type:

str

Default Value:

''

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The displayed label.

Adw.ButtonContent.props.use_underline
Name:

use-underline

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether an underline in the text indicates a mnemonic.

The mnemonic can be used to activate the parent button.

See [property`ButtonContent`:py:data::label<Adw.ButtonContent.props.label>].