Gtk.ModelButton

g Atk.ImplementorIface Atk.ImplementorIface Gtk.Widget Gtk.Widget Atk.ImplementorIface->Gtk.Widget GObject.GInterface GObject.GInterface GObject.GInterface->Atk.ImplementorIface Gtk.Actionable Gtk.Actionable GObject.GInterface->Gtk.Actionable Gtk.Activatable Gtk.Activatable GObject.GInterface->Gtk.Activatable Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.InitiallyUnowned GObject.InitiallyUnowned GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Button Gtk.Button Gtk.Actionable->Gtk.Button Gtk.Activatable->Gtk.Button Gtk.Bin Gtk.Bin Gtk.Bin->Gtk.Button Gtk.Buildable->Gtk.Widget Gtk.ModelButton Gtk.ModelButton Gtk.Button->Gtk.ModelButton Gtk.Container Gtk.Container Gtk.Container->Gtk.Bin Gtk.Widget->Gtk.Container

Subclasses:

None

Methods

Inherited:

Gtk.Button (29), Gtk.Bin (1), Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10), Gtk.Actionable (5), Gtk.Activatable (6)

Structs:

Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)

class

new ()

Virtual Methods

Inherited:

Gtk.Button (6), Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10), Gtk.Actionable (4), Gtk.Activatable (2)

Properties

Inherited:

Gtk.Button (9), Gtk.Container (3), Gtk.Widget (39), Gtk.Actionable (2), Gtk.Activatable (2)

Name

Type

Flags

Short Description

active

bool

r/w/en

Active

centered

bool

r/w/en

Whether to center the contents

icon

Gio.Icon

r/w/en

The icon

iconic

bool

r/w/en

Whether to prefer the icon over text

inverted

bool

r/w/en

Whether the menu is a parent

menu-name

str

r/w/en

The name of the menu to open

role

Gtk.ButtonRole

r/w/en

The role of this button

text

str

r/w/en

The text

use-markup

bool

r/w/en

The text of the button includes XML markup. See Pango.parse_markup()

Style Properties

Inherited:

Gtk.Button (7), Gtk.Widget (17)

Signals

Inherited:

Gtk.Button (6), Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Fields

Inherited:

Gtk.Button (6), Gtk.Container (4), Gtk.Widget (69), GObject.Object (1)

Class Details

class Gtk.ModelButton(*args, **kwargs)
Bases:

Gtk.Button

Abstract:

No

Gtk.ModelButton is a button class that can use a Gio.Action as its model. In contrast to Gtk.ToggleButton or Gtk.RadioButton, which can also be backed by a Gio.Action via the Gtk.Actionable :action-name property, Gtk.ModelButton will adapt its appearance according to the kind of action it is backed by, and appear either as a plain, check or radio button.

Model buttons are used when popovers from a menu model with Gtk.Popover.new_from_model(); they can also be used manually in a Gtk.PopoverMenu.

When the action is specified via the Gtk.Actionable :action-name and Gtk.Actionable :action-target properties, the role of the button (i.e. whether it is a plain, check or radio button) is determined by the type of the action and doesn’t have to be explicitly specified with the Gtk.ModelButton :role property.

The content of the button is specified by the Gtk.ModelButton :text and Gtk.ModelButton :icon properties.

The appearance of model buttons can be influenced with the Gtk.ModelButton :centered and Gtk.ModelButton :iconic properties.

Model buttons have built-in support for submenus in Gtk.PopoverMenu. To make a Gtk.ModelButton that opens a submenu when activated, set the Gtk.ModelButton :menu-name property. To make a button that goes back to the parent menu, you should set the Gtk.ModelButton :inverted property to place the submenu indicator at the opposite side.

Example
<object class="GtkPopoverMenu">
  <child>
    <object class="GtkBox">
      <property name="visible">True</property>
      <property name="margin">10</property>
      <child>
        <object class="GtkModelButton">
          <property name="visible">True</property>
          <property name="action-name">view.cut</property>
          <property name="text" translatable="yes">Cut</property>
        </object>
      </child>
      <child>
        <object class="GtkModelButton">
          <property name="visible">True</property>
          <property name="action-name">view.copy</property>
          <property name="text" translatable="yes">Copy</property>
        </object>
      </child>
      <child>
        <object class="GtkModelButton">
          <property name="visible">True</property>
          <property name="action-name">view.paste</property>
          <property name="text" translatable="yes">Paste</property>
        </object>
      </child>
    </object>
  </child>
</object>
CSS nodes
modelbutton
├── <child>
╰── check
modelbutton
├── <child>
╰── radio
modelbutton
├── <child>
╰── arrow

Gtk.ModelButton has a main CSS node with name modelbutton, and a subnode, which will have the name check, radio or arrow, depending on the role of the button and whether it has a menu name set.

The subnode is positioned before or after the content nodes and gets the .left or .right style class, depending on where it is located.

button.model
├── <child>
╰── check

Iconic model buttons (see Gtk.ModelButton :iconic) change the name of their main node to button and add a .model style class to it. The indicator subnode is invisible in this case.

classmethod new()[source]
Returns:

the newly created Gtk.ModelButton widget

Return type:

Gtk.Widget

Creates a new Gtk.ModelButton.

New in version 3.16.

Property Details

Gtk.ModelButton.props.active
Name:

active

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The state of the button. This is reflecting the state of the associated Gio.Action.

New in version 3.16.

Gtk.ModelButton.props.centered
Name:

centered

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether to render the button contents centered instead of left-aligned. This property should be set for title-like items.

New in version 3.16.

Gtk.ModelButton.props.icon
Name:

icon

Type:

Gio.Icon

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

A Gio.Icon that will be used if iconic appearance for the button is desired.

New in version 3.16.

Gtk.ModelButton.props.iconic
Name:

iconic

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

If this property is set, the button will show an icon if one is set. If no icon is set, the text will be used. This is typically used for horizontal sections of linked buttons.

New in version 3.16.

Gtk.ModelButton.props.inverted
Name:

inverted

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Whether to show the submenu indicator at the opposite side than normal. This property should be set for model buttons that ‘go back’ to a parent menu.

New in version 3.16.

Gtk.ModelButton.props.menu_name
Name:

menu-name

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The name of a submenu to open when the button is activated. If this is set, the button should not have an action associated with it.

New in version 3.16.

Gtk.ModelButton.props.role
Name:

role

Type:

Gtk.ButtonRole

Default Value:

Gtk.ButtonRole.NORMAL

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

Specifies whether the button is a plain, check or radio button. When Gtk.Actionable :action-name is set, the role will be determined from the action and does not have to be set explicitly.

New in version 3.16.

Gtk.ModelButton.props.text
Name:

text

Type:

str

Default Value:

''

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The label for the button.

New in version 3.16.

Gtk.ModelButton.props.use_markup
Name:

use-markup

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

If True, XML tags in the text of the button are interpreted as by Pango.parse_markup() to format the enclosed spans of text. If False, the text will be displayed verbatim.

New in version 3.24.