MenuItem

The #GtkMenuItem widget and the derived widgets are the only valid children for menus. Their function is to correctly handle highlighting, alignment, events and submenus.

As a GtkMenuItem derives from #GtkBin it can hold any valid child widget, although only a few are really useful.

By default, a GtkMenuItem sets a #GtkAccelLabel as its child. GtkMenuItem has direct functions to set the label and its mnemonic. For more advanced label settings, you can fetch the child widget from the GtkBin.

An example for setting markup and accelerator on a MenuItem:

GtkWidget *menu_item = gtk_menu_item_new_with_label ("Example Menu Item");

GtkWidget *child = gtk_bin_get_child (GTK_BIN (menu_item));
gtk_label_set_markup (GTK_LABEL (child), "<i>new label</i> with <b>markup</b>");
gtk_accel_label_set_accel (GTK_ACCEL_LABEL (child), GDK_KEY_1, 0);

GtkMenuItem as GtkBuildable

The GtkMenuItem implementation of the #GtkBuildable interface supports adding a submenu by specifying “submenu” as the “type” attribute of a <child> element.

An example of UI definition fragment with submenus:

<object class="GtkMenuItem">
  <child type="submenu">
    <object class="GtkMenu"/>
  </child>
</object>

CSS nodes

menuitem
├── <child>
╰── [arrow.right]

GtkMenuItem has a single CSS node with name menuitem. If the menuitem has a submenu, it gets another CSS node with name arrow, which has the .left or .right style class.

class MenuItem : Bin , Actionable , Activatable {}

Constructors

this
this(void* ptr, Flag!"Take" take)
this
this()

Creates a new #GtkMenuItem.

Members

Functions

activate
void activate()

Emits the #GtkMenuItem::activate signal on the given item

connectActivate
gulong connectActivate(T callback, Flag!"After" after)

Connect to Activate signal.

connectActivateItem
gulong connectActivateItem(T callback, Flag!"After" after)

Connect to ActivateItem signal.

connectDeselect
gulong connectDeselect(T callback, Flag!"After" after)

Connect to Deselect signal.

connectSelect
gulong connectSelect(T callback, Flag!"After" after)

Connect to Select signal.

connectToggleSizeAllocate
gulong connectToggleSizeAllocate(T callback, Flag!"After" after)

Connect to ToggleSizeAllocate signal.

connectToggleSizeRequest
gulong connectToggleSizeRequest(T callback, Flag!"After" after)

Connect to ToggleSizeRequest signal.

deselect
void deselect()

Emits the #GtkMenuItem::deselect signal on the given item.

getAccelPath
string getAccelPath()

Retrieve the accelerator path that was previously set on menu_item.

getLabel
string getLabel()

Sets text on the menu_item label

getReserveIndicator
bool getReserveIndicator()

Returns whether the menu_item reserves space for the submenu indicator, regardless if it has a submenu or not.

getRightJustified
bool getRightJustified()

Gets whether the menu item appears justified at the right side of the menu bar.

getSubmenu
gtk.widget.Widget getSubmenu()

Gets the submenu underneath this menu item, if any. See gtk.menu_item.MenuItem.setSubmenu.

getUseUnderline
bool getUseUnderline()

Checks if an underline in the text indicates the next character should be used for the mnemonic accelerator key.

select
void select()

Emits the #GtkMenuItem::select signal on the given item.

self
MenuItem self()

Returns this, for use in with statements.

setAccelPath
void setAccelPath(string accelPath)

Set the accelerator path on menu_item, through which runtime changes of the menu item’s accelerator caused by the user can be identified and saved to persistent storage (see gtk.accel_map.AccelMap.save on this). To set up a default accelerator for this menu item, call gtk.accel_map.AccelMap.addEntry with the same accel_path. See also gtk.accel_map.AccelMap.addEntry on the specifics of accelerator paths, and gtk.menu.Menu.setAccelPath for a more convenient variant of this function.

setLabel
void setLabel(string label)

Sets text on the menu_item label

setReserveIndicator
void setReserveIndicator(bool reserve)

Sets whether the menu_item should reserve space for the submenu indicator, regardless if it actually has a submenu or not.

setRightJustified
void setRightJustified(bool rightJustified)

Sets whether the menu item appears justified at the right side of a menu bar. This was traditionally done for “Help” menu items, but is now considered a bad idea. (If the widget layout is reversed for a right-to-left language like Hebrew or Arabic, right-justified-menu-items appear at the left.)

setSubmenu
void setSubmenu(gtk.menu.Menu submenu)

Sets or replaces the menu item’s submenu, or removes it when a null submenu is passed.

setUseUnderline
void setUseUnderline(bool setting)

If true, an underline in the text indicates the next character should be used for the mnemonic accelerator key.

toggleSizeAllocate
void toggleSizeAllocate(int allocation)

Emits the #GtkMenuItem::toggle-size-allocate signal on the given item.

toggleSizeRequest
void toggleSizeRequest(int requisition)

Emits the #GtkMenuItem::toggle-size-request signal on the given item.

Properties

_gType
GType _gType [@property getter]
accelPath
string accelPath [@property getter]

Get accelPath property.

accelPath
string accelPath [@property setter]

Set accelPath property.

label
string label [@property getter]

Get label property.

label
string label [@property setter]

Set label property.

rightJustified
bool rightJustified [@property getter]

Get rightJustified property.

rightJustified
bool rightJustified [@property setter]

Set rightJustified property.

submenu
gtk.menu.Menu submenu [@property getter]

Get submenu property.

submenu
gtk.menu.Menu submenu [@property setter]

Set submenu property.

useUnderline
bool useUnderline [@property getter]

Get useUnderline property.

useUnderline
bool useUnderline [@property setter]

Set useUnderline property.

Static functions

_getGType
GType _getGType()
builder
MenuItemGidBuilder builder()

Get builder for gtk.menu_item.MenuItem

newWithLabel
gtk.menu_item.MenuItem newWithLabel(string label)

Creates a new #GtkMenuItem whose child is a #GtkLabel.

newWithMnemonic
gtk.menu_item.MenuItem newWithMnemonic(string label)

Creates a new #GtkMenuItem containing a label.

Mixed In Members

From mixin ActionableT!()

actionName
string actionName [@property getter]
actionName
string actionName [@property setter]
actionTarget
glib.variant.Variant actionTarget [@property getter]
actionTarget
glib.variant.Variant actionTarget [@property setter]
getActionName
string getActionName()

Gets the action name for actionable.

getActionTargetValue
glib.variant.Variant getActionTargetValue()

Gets the current target value of actionable.

setActionName
void setActionName(string actionName)

Specifies the name of the action with which this widget should be associated. If action_name is null then the widget will be unassociated from any previous action.

setActionTargetValue
void setActionTargetValue(glib.variant.Variant targetValue)

Sets the target value of an actionable widget.

setDetailedActionName
void setDetailedActionName(string detailedActionName)

Sets the action-name and associated string target value of an actionable widget.

From mixin ActivatableT!()

relatedAction
gtk.action.Action relatedAction [@property getter]

Get relatedAction property.

relatedAction
gtk.action.Action relatedAction [@property setter]

Set relatedAction property.

useActionAppearance
bool useActionAppearance [@property getter]

Get useActionAppearance property.

useActionAppearance
bool useActionAppearance [@property setter]

Set useActionAppearance property.

doSetRelatedAction
void doSetRelatedAction(gtk.action.Action action)

This is a utility function for #GtkActivatable implementors.

getRelatedAction
gtk.action.Action getRelatedAction()

Gets the related #GtkAction for activatable.

getUseActionAppearance
bool getUseActionAppearance()

Gets whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance.

setRelatedAction
void setRelatedAction(gtk.action.Action action)

Sets the related action on the activatable object.

setUseActionAppearance
void setUseActionAppearance(bool useAppearance)

Sets whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance

syncActionProperties
void syncActionProperties(gtk.action.Action action)

This is called to update the activatable completely, this is called internally when the #GtkActivatable:related-action property is set or unset and by the implementing class when #GtkActivatable:use-action-appearance changes.

Inherited Members

From Bin

_getGType
GType _getGType()
_gType
GType _gType [@property getter]
self
Bin self()

Returns this, for use in with statements.

builder
BinGidBuilder builder()

Get builder for gtk.bin.Bin

getChild
gtk.widget.Widget getChild()

Gets the child of the #GtkBin, or null if the bin contains no child widget. The returned widget does not have a reference added, so you do not need to unref it.

From Actionable

_getGType
GType _getGType()
actionName
string actionName [@property getter]
actionName
string actionName [@property setter]
actionTarget
glib.variant.Variant actionTarget [@property getter]
actionTarget
glib.variant.Variant actionTarget [@property setter]
getActionName
string getActionName()

Gets the action name for actionable.

getActionTargetValue
glib.variant.Variant getActionTargetValue()

Gets the current target value of actionable.

setActionName
void setActionName(string actionName)

Specifies the name of the action with which this widget should be associated. If action_name is null then the widget will be unassociated from any previous action.

setActionTargetValue
void setActionTargetValue(glib.variant.Variant targetValue)

Sets the target value of an actionable widget.

setDetailedActionName
void setDetailedActionName(string detailedActionName)

Sets the action-name and associated string target value of an actionable widget.

From Activatable

_getGType
GType _getGType()
relatedAction
gtk.action.Action relatedAction [@property getter]

Get relatedAction property.

relatedAction
gtk.action.Action relatedAction [@property setter]

Set relatedAction property.

useActionAppearance
bool useActionAppearance [@property getter]

Get useActionAppearance property.

useActionAppearance
bool useActionAppearance [@property setter]

Set useActionAppearance property.

doSetRelatedAction
void doSetRelatedAction(gtk.action.Action action)

This is a utility function for #GtkActivatable implementors.

getRelatedAction
gtk.action.Action getRelatedAction()

Gets the related #GtkAction for activatable.

getUseActionAppearance
bool getUseActionAppearance()

Gets whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance.

setRelatedAction
void setRelatedAction(gtk.action.Action action)

Sets the related action on the activatable object.

setUseActionAppearance
void setUseActionAppearance(bool useAppearance)

Sets whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance

syncActionProperties
void syncActionProperties(gtk.action.Action action)

This is called to update the activatable completely, this is called internally when the #GtkActivatable:related-action property is set or unset and by the implementing class when #GtkActivatable:use-action-appearance changes.