## GtkModelButton

GtkModelButton — A button that uses a GAction as model

## Functions

GtkWidget * | gtk_model_button_new ()

## Properties

gboolean | active | Read / Write
gboolean | centered | Read / Write
GIcon * | icon | Read / Write
gboolean | iconic | Read / Write
gboolean | inverted | Read / Write
gchar * | menu-name | Read / Write
GtkButtonRole | role | Read / Write
gchar * | text | Read / Write
gboolean | use-markup | Read / Write

## Types and Values

| GtkModelButton
enum | GtkButtonRole

## Object Hierarchy

        GObject
        ╰── GInitiallyUnowned
            ╰── GtkWidget
                ╰── GtkContainer
                    ╰── GtkBin
                        ╰── GtkButton
                            ╰── GtkModelButton

## Implemented Interfaces

GtkModelButton implements AtkImplementorIface, GtkBuildable, GtkActionable and GtkActivatable.

## Includes

    #include <gtk/gtk.h>

## Description

GtkModelButton is a button class that can use a GAction as its model. In contrast to GtkToggleButton or GtkRadioButton, which can also be backed by a GAction via the “action-name” property, GtkModelButton 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 GtkPopoverMenu.

When the action is specified via the “action-name” and “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 “role” property.

The content of the button is specified by the “text” and “icon” properties.

The appearance of model buttons can be influenced with the “centered” and “iconic” properties.

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

### Example

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29

    <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

    1
    2
    3

    modelbutton
    ├── <child>
    ╰── check

    1
    2
    3

    modelbutton
    ├── <child>
    ╰── radio

    1
    2
    3

    modelbutton
    ├── <child>
    ╰── arrow

GtkModelButton 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.

    1
    2
    3

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

Iconic model buttons (see “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.

## Functions

### gtk_model_button_new ()

    GtkWidget *
    gtk_model_button_new (void);

Creates a new GtkModelButton.

#### Returns

the newly created GtkModelButton widget

Since: 3.16

## Types and Values

### GtkModelButton

    typedef struct _GtkModelButton GtkModelButton;

### enum GtkButtonRole

The role specifies the desired appearance of a GtkModelButton.

#### Members

GTK_BUTTON_ROLE_NORMAL | A plain button |
GTK_BUTTON_ROLE_CHECK | A check button |
GTK_BUTTON_ROLE_RADIO | A radio button |

## Property Details

### The `“active”` property

      “active”                   gboolean

The state of the button. This is reflecting the state of the associated GAction.

Owner: GtkModelButton

Flags: Read / Write

Default value: FALSE

Since: 3.16

### The `“centered”` property

      “centered”                 gboolean

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

Owner: GtkModelButton

Flags: Read / Write

Default value: FALSE

Since: 3.16

### The `“icon”` property

      “icon”                     GIcon *

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

Owner: GtkModelButton

Flags: Read / Write

Since: 3.16

### The `“iconic”` property

      “iconic”                   gboolean

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.

Owner: GtkModelButton

Flags: Read / Write

Default value: FALSE

Since: 3.16

### The `“inverted”` property

      “inverted”                 gboolean

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.

Owner: GtkModelButton

Flags: Read / Write

Default value: FALSE

Since: 3.16

### The `“menu-name”` property

      “menu-name”                gchar *

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.

Owner: GtkModelButton

Flags: Read / Write

Default value: NULL

Since: 3.16

### The `“role”` property

      “role”                     GtkButtonRole

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

Owner: GtkModelButton

Flags: Read / Write

Default value: GTK_BUTTON_ROLE_NORMAL

Since: 3.16

### The `“text”` property

      “text”                     gchar *

The label for the button.

Owner: GtkModelButton

Flags: Read / Write

Default value: ""

Since: 3.16

### The `“use-markup”` property

      “use-markup”               gboolean

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.

Owner: GtkModelButton

Flags: Read / Write

Default value: FALSE

Since: 3.24