## GtkMenuButton

GtkMenuButton — A widget that shows a menu when clicked on

## Functions

GtkWidget * | gtk_menu_button_new ()
void | gtk_menu_button_set_popup ()
GtkMenu * | gtk_menu_button_get_popup ()
void | gtk_menu_button_set_menu_model ()
GMenuModel * | gtk_menu_button_get_menu_model ()
void | gtk_menu_button_set_direction ()
GtkArrowType | gtk_menu_button_get_direction ()
void | gtk_menu_button_set_align_widget ()
GtkWidget * | gtk_menu_button_get_align_widget ()

## Properties

GtkContainer * | align-widget | Read / Write
GtkArrowType | direction | Read / Write
GMenuModel * | menu-model | Read / Write
GtkMenu * | popup | Read / Write

## Types and Values

struct | GtkMenuButton

## Object Hierarchy

        GObject
        ╰── GInitiallyUnowned
            ╰── GtkWidget
                ╰── GtkContainer
                    ╰── GtkBin
                        ╰── GtkButton
                            ╰── GtkToggleButton
                                ╰── GtkMenuButton

## Implemented Interfaces

GtkMenuButton implements AtkImplementorIface, GtkBuildable, GtkActionable and GtkActivatable.

## Includes

    #include <gtk/gtk.h>

## Description

The GtkMenuButton widget is used to display a menu when clicked on. This menu can be provided either as a GtkMenu, or an abstract GMenuModel.

The GtkMenuButton widget can hold any valid child widget. That is, it can hold almost any other standard GtkWidget. The most commonly used child is the provided GtkArrow.

The positioning of the menu is determined by the “direction” property of the menu button and the “halign” or “valign” properties of the menu. For example, when the direction is `GTK_ARROW_DOWN` and the horizontal alignment is `GTK_ALIGN_START`, the menu will be positioned below the button, with the starting edge (depending on the text direction) of the menu aligned with the starting edge of the button. If there is not enough space below the button, the menu is popped up above the button instead. If the alignment would move part of the menu offscreen, it is 'pushed in'.

| halign = start | halign = center | halign = end
direction = down |  |  |
direction = up |  |  |

| direction = left | direction = right
valign = start |  |
valign = center |  |
valign = end |  |

## Functions

### gtk_menu_button_new ()

    GtkWidget *
    gtk_menu_button_new (void);

Creates a new GtkMenuButton widget with downwards-pointing arrow as the only child. You can replace the child widget with another GtkWidget should you wish to.

#### Returns

The newly created GtkMenuButton widget.

Since 3.6

### gtk_menu_button_set_popup ()

    void
    gtk_menu_button_set_popup (GtkMenuButton *menu_button,
                               GtkWidget *popup);

Sets the GtkMenu that will be popped up when the button is clicked, or `NULL` to disable the button. If “menu-model” is set, it will be set to `NULL`.

#### Parameters

menu_button | a GtkMenuButton |
popup | a GtkMenu. | [allow-none]

Since 3.6

### gtk_menu_button_get_popup ()

    GtkMenu *
    gtk_menu_button_get_popup (GtkMenuButton *menu_button);

Returns the GtkMenu that pops out of the button.

#### Parameters

menu_button | a GtkMenuButton |

#### Returns

a GtkMenu or `NULL`.

[transfer none]

Since 3.6

### gtk_menu_button_set_menu_model ()

    void
    gtk_menu_button_set_menu_model (GtkMenuButton *menu_button,
                                    GMenuModel *menu_model);

Sets the GMenuModel from which the “popup” property will be filled in, or `NULL` to disable the button.

The GtkMenu will be created with `gtk_menu_new_from_model()`, so actions will be connected as documented there.

If “popup” is already set, then its content will be lost and replaced by our newly created GtkMenu.

#### Parameters

menu_button | a GtkMenuButton |
menu_model | a GMenuModel. | [allow-none]

Since 3.6

### gtk_menu_button_get_menu_model ()

    GMenuModel *
    gtk_menu_button_get_menu_model (GtkMenuButton *menu_button);

Returns the GMenuModel used to generate the menu.

#### Parameters

menu_button | a GtkMenuButton |

#### Returns

a GMenuModel or `NULL`.

[transfer none]

Since 3.6

### gtk_menu_button_set_direction ()

    void
    gtk_menu_button_set_direction (GtkMenuButton *menu_button,
                                   GtkArrowType direction);

Sets the direction in which the menu will be popped up, as well as changing the arrow's direction. The child will not be changed to an arrow if it was customized.

If the menu when popped out would have collided with screen edges, we will do our best to keep it inside the screen and fully visible.

If you pass `GTK_ARROW_NONE` for a `direction` , the menu will behave as if you passed `GTK_ARROW_DOWN` (although you won't see any arrows).

#### Parameters

menu_button | a GtkMenuButton |
direction | a GtkArrowType |

Since 3.6

### gtk_menu_button_get_direction ()

    GtkArrowType
    gtk_menu_button_get_direction (GtkMenuButton *menu_button);

Returns the direction the menu will be pointing at when popped up.

#### Parameters

menu_button | a GtkMenuButton |

#### Returns

a GtkArrowType value.

Since 3.6

### gtk_menu_button_set_align_widget ()

    void
    gtk_menu_button_set_align_widget (GtkMenuButton *menu_button,
                                      GtkWidget *align_widget);

Sets the GtkWidget to use to line the menu with when popped up. Note that the `align_widget` must contain the GtkMenuButton itself.

Setting it to `NULL` means that the popup menu will be aligned with the button itself.

#### Parameters

menu_button | a GtkMenuButton |
align_widget | a GtkWidget. | [allow-none]

Since 3.6

### gtk_menu_button_get_align_widget ()

    GtkWidget *
    gtk_menu_button_get_align_widget (GtkMenuButton *menu_button);

Returns the parent GtkWidget to use to line up with menu.

#### Parameters

menu_button | a GtkMenuButton |

#### Returns

a GtkWidget value or `NULL`.

[transfer none]

Since 3.6

## Types and Values

### struct GtkMenuButton

    struct GtkMenuButton;

## Property Details

### The `“align-widget”` property

      “align-widget”             GtkContainer *

The GtkWidget to use to align the popup menu with.

Flags: Read / Write

Since 3.6

### The `“direction”` property

      “direction”                GtkArrowType

The GtkArrowType representing the direction in which the menu will be popped out.

Flags: Read / Write

Default value: GTK_ARROW_DOWN

Since 3.6

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

      “menu-model”               GMenuModel *

The GMenuModel from which the menu to pop up will be created. See `gtk_menu_button_set_menu_model()` for the interaction with the “popup” property.

Flags: Read / Write

Since 3.6

### The `“popup”` property

      “popup”                    GtkMenu *

The GtkMenu that will be popped up when the button is clicked.

Flags: Read / Write

Since 3.6