gtk.menu_item

Module for [MenuItem] class

Types 3

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.

Methods
GType _gType() @property
MenuItem self()Returns `this`, for use in `with` statements.
MenuItemGidBuilder builder()Get builder for [gtk.menu_item.MenuItem] Returns: New builder object
string accelPath() @propertyGet `accelPath` property. Returns: Sets the accelerator path of the menu item, through which runtime changes of the menu item's accelerator caused by the user can be identified and saved to persist...
void accelPath(string propval) @propertySet `accelPath` property. Params: propval = Sets the accelerator path of the menu item, through which runtime changes of the menu item's accelerator caused by the user can be identified and saved t...
string label() @propertyGet `label` property. Returns: The text for the child label.
void label(string propval) @propertySet `label` property. Params: propval = The text for the child label.
bool rightJustified() @propertyGet `rightJustified` property. Returns: Sets whether the menu item appears justified at the right side of a menu bar.
void rightJustified(bool propval) @propertySet `rightJustified` property. Params: propval = Sets whether the menu item appears justified at the right side of a menu bar.
gtk.menu.Menu submenu() @propertyGet `submenu` property. Returns: The submenu attached to the menu item, or null if it has none.
void submenu(gtk.menu.Menu propval) @propertySet `submenu` property. Params: propval = The submenu attached to the menu item, or null if it has none.
bool useUnderline() @propertyGet `useUnderline` property. Returns: true if underlines in the text indicate mnemonics.
void useUnderline(bool propval) @propertySet `useUnderline` property. Params: propval = true if underlines in the text indicate mnemonics.
gtk.menu_item.MenuItem newWithLabel(string label)Creates a new #GtkMenuItem whose child is a #GtkLabel.
gtk.menu_item.MenuItem newWithMnemonic(string label)Creates a new #GtkMenuItem containing a label.
void activate()Emits the #GtkMenuItem::activate signal on the given item
void deselect()Emits the #GtkMenuItem::deselect signal on the given item.
string getAccelPath()Retrieve the accelerator path that was previously set on menu_item.
string getLabel()Sets text on the menuitem label Returns: The text in the menuitem label. This is the internal string used by the label, and must not be modified.
bool getReserveIndicator()Returns whether the menuitem reserves space for the submenu indicator, regardless if it has a submenu or not. Returns: true if menuitem always reserves space for the submenu indicator
bool getRightJustified()Gets whether the menu item appears justified at the right side of the menu bar. Returns: true if the menu item will appear at the far right if added to a menu bar.
gtk.widget.Widget getSubmenu()Gets the submenu underneath this menu item, if any. See [gtk.menu_item.MenuItem.setSubmenu]. Returns: submenu for this menu item, or null if none
bool getUseUnderline()Checks if an underline in the text indicates the next character should be used for the mnemonic accelerator key. Returns: true if an embedded underline in the label indicates the mnemonic accelerat...
void select()Emits the #GtkMenuItem::select signal on the given item.
void setAccelPath(string accelPath = null)Set the accelerator path on menuitem, through which runtime changes of the menu item’s accelerator caused by the user can be identified and saved to persistent storage (see [gtk.accelmap.AccelMap...
void setLabel(string label)Sets text on the menu_item label
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.
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 rever...
void setSubmenu(gtk.menu.Menu submenu = null)Sets or replaces the menu item’s submenu, or removes it when a null submenu is passed.
void setUseUnderline(bool setting)If true, an underline in the text indicates the next character should be used for the mnemonic accelerator key.
void toggleSizeAllocate(int allocation)Emits the #GtkMenuItem::toggle-size-allocate signal on the given item.
void toggleSizeRequest(ref int requisition)Emits the #GtkMenuItem::toggle-size-request signal on the given item.
gulong connectActivate(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.menu_item.MenuItem))) && Parameters!T.length < 2)Connect to `Activate` signal.
gulong connectActivateItem(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.menu_item.MenuItem))) && Parameters!T.length < 2)Connect to `ActivateItem` signal.
gulong connectDeselect(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.menu_item.MenuItem))) && Parameters!T.length < 2)Connect to `Deselect` signal.
gulong connectSelect(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : gtk.menu_item.MenuItem))) && Parameters!T.length < 2)Connect to `Select` signal.
gulong connectToggleSizeAllocate(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == int))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.menu_item.MenuItem))) && Parameters!T.length < 3)Connect to `ToggleSizeAllocate` signal.
gulong connectToggleSizeRequest(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == void *))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.menu_item.MenuItem))) && Parameters!T.length < 3)Connect to `ToggleSizeRequest` signal.
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a new #GtkMenuItem. Returns: the newly created #GtkMenuItem
Methods
T accelPath(string propval)Set `accelPath` property. Params: propval = Sets the accelerator path of the menu item, through which runtime changes of the menu item's accelerator caused by the user can be identified and saved t...
T label(string propval)Set `label` property. Params: propval = The text for the child label. Returns: Builder instance for fluent chaining
T rightJustified(bool propval)Set `rightJustified` property. Params: propval = Sets whether the menu item appears justified at the right side of a menu bar. Returns: Builder instance for fluent chaining
T submenu(gtk.menu.Menu propval)Set `submenu` property. Params: propval = The submenu attached to the menu item, or null if it has none. Returns: Builder instance for fluent chaining
T useUnderline(bool propval)Set `useUnderline` property. Params: propval = true if underlines in the text indicate mnemonics. Returns: Builder instance for fluent chaining

Fluent builder for [gtk.menu_item.MenuItem]

Methods