Package: gtk

Class gtk-model-button

Superclasses

Documented Subclasses

None

Direct Slots

active
The active property of type :boolean (Read / Write)
The state of the button. This is reflecting the state of the associated g-action.
Default value: false
centered
The centered property of type :boolean (Read / Write)
Whether to render the button contents centered instead of left-aligned. This property should be set for title-like items.
Default value: false
icon
The icon property of type g-icon (Read / Write)
An icon that will be used if iconic appearance for the button is desired.
iconic
The iconic property of type :boolean (Read / Write)
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.
Default value: false
inverted
The inverted property of type :boolean (Read / Write)
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.
Default value: false
menu-name
The menu-name property of type :string (Read / Write)
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.
Default value: nil
role
The role property of type gtk-button-role (Read / Write)
Specifies whether the button is a plain, check or radio button. When the action-name property is set, the role will be determined from the action and does not have to be set explicitly.
Default value: :normal
text
The text property of type :string (Read / Write)
The label for the button.
Default value: ""
use-markup
The use-markjup property of type :boolean (Read / Write)
If true, XML tags in the text of the button are interpreted to format the enclosed spans of text. If false, the text will be displayed verbatim. Since 3.24
Default value: false

Details

The gtk-model-button class is a button class that can use a g-action object as its model. In contrast to the gtk-toggle-button or gtk-radio-button classes, which can also be backed by a g-action object via the action-name property, the gtk-model-button widget 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 with popovers from a menu model with the gtk-popover-new-from-model function. They can also be used manually in a gtk-popover-menu widget.

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 does not 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 the gtk-popover-menu widget. To make a gtk-model-button widget 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

<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
The gtk-model-button implementation 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 the iconic property, 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.
 

Slot Access Functions

Inherited Slot Access Functions

2021-12-23