gtk.image_menu_item
Module for [ImageMenuItem] class
Types 3
A GtkImageMenuItem is a menu item which has an icon next to the text label.
This is functionally equivalent to:
GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
GtkWidget *icon = gtk_image_new_from_icon_name ("folder-music-symbolic", GTK_ICON_SIZE_MENU);
GtkWidget *label = gtk_label_new ("Music");
GtkWidget *menu_item = gtk_menu_item_new ();
gtk_container_add (GTK_CONTAINER (box), icon);
gtk_container_add (GTK_CONTAINER (box), label);
gtk_container_add (GTK_CONTAINER (menu_item), box);
gtk_widget_show_all (menu_item);Note that the user may disable display of menu icons using the #GtkSettings:gtk-menu-images setting, so make sure to still fill in the text label. If you want to ensure that your menu items show an icon you are strongly encouraged to use a #GtkMenuItem with a #GtkImage instead.
#GtkImageMenuItem has been deprecated since GTK+ 3.10. If you want to display an icon in a menu item, you should use #GtkMenuItem and pack a #GtkBox with a #GtkImage and a #GtkLabel instead. You should also consider using #GtkBuilder and the XML #GMenu description for creating menus, by following the [GMenu guide][https://developer.gnome.org/GMenu/]. You should consider using icons in menu items only sparingly, and for "objects" (or "nouns") elements only, like bookmarks, files, and links; "actions" (or "verbs") should not have icons.
Furthermore, if you would like to display keyboard accelerator, you must pack the accel label into the box using [gtk.box.Box.packEnd] and align the label, otherwise the accelerator will not display correctly. The following code snippet adds a keyboard accelerator to the menu item, with a key binding of Ctrl+M:
GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
GtkWidget *icon = gtk_image_new_from_icon_name ("folder-music-symbolic", GTK_ICON_SIZE_MENU);
GtkWidget *label = gtk_accel_label_new ("Music");
GtkWidget *menu_item = gtk_menu_item_new ();
GtkAccelGroup *accel_group = gtk_accel_group_new ();
gtk_container_add (GTK_CONTAINER (box), icon);
gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_widget_add_accelerator (menu_item, "activate", accel_group,
GDK_KEY_m, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), menu_item);
gtk_box_pack_end (GTK_BOX (box), label, TRUE, TRUE, 0);
gtk_container_add (GTK_CONTAINER (menu_item), box);
gtk_widget_show_all (menu_item);ImageMenuItem self()Returns `this`, for use in `with` statements.ImageMenuItemGidBuilder builder()Get builder for [gtk.imagemenuitem.ImageMenuItem] Returns: New builder objectvoid accelGroup(gtk.accel_group.AccelGroup propval) @propertySet `accelGroup` property. Params: propval = The Accel Group to use for stock accelerator keysbool alwaysShowImage() @propertyGet `alwaysShowImage` property. Returns: If true, the menu item will always show the image, if available.void alwaysShowImage(bool propval) @propertySet `alwaysShowImage` property. Params: propval = If true, the menu item will always show the image, if available.gtk.widget.Widget image() @propertyGet `image` property. Returns: Child widget to appear next to the menu text.void image(gtk.widget.Widget propval) @propertySet `image` property. Params: propval = Child widget to appear next to the menu text.bool useStock() @propertyGet `useStock` property. Returns: If true, the label set in the menuitem is used as a stock id to select the stock item for the item.void useStock(bool propval) @propertySet `useStock` property. Params: propval = If true, the label set in the menuitem is used as a stock id to select the stock item for the item.gtk.image_menu_item.ImageMenuItem newFromStock(string stockId, gtk.accel_group.AccelGroup accelGroup = null)Creates a new #GtkImageMenuItem containing the image and text from a stock item. Some stock ids have preprocessor macros like #GTKSTOCKOK and #GTKSTOCKAPPLY.gtk.image_menu_item.ImageMenuItem newWithLabel(string label)Creates a new #GtkImageMenuItem containing a label.gtk.image_menu_item.ImageMenuItem newWithMnemonic(string label)Creates a new #GtkImageMenuItem containing a label. The label will be created using [gtk.label.Label.newWithMnemonic], so underscores in label indicate the mnemonic for the menu item.bool getAlwaysShowImage()Returns whether the menu item will ignore the #GtkSettings:gtk-menu-images setting and always show the image, if available. Returns: true if the menu item will always show the imagegtk.widget.Widget getImage()Gets the widget that is currently set as the image of imagemenuitem. See [gtk.imagemenuitem.ImageMenuItem.setImage]. Returns: the widget set as image of imagemenuitembool getUseStock()Checks whether the label set in the menuitem is used as a stock id to select the stock item for the item. Returns: true if the label set in the menuitem is used as a stock id to select the stock it...void setAccelGroup(gtk.accel_group.AccelGroup accelGroup)Specifies an accelgroup to add the menu items accelerator to (this only applies to stock items so a stock item must already be set, make sure to call [gtk.imagemenuitem.ImageMenuItem.setUseStock] a...void setAlwaysShowImage(bool alwaysShow)If true, the menu item will ignore the #GtkSettings:gtk-menu-images setting and always show the image, if available.void setImage(gtk.widget.Widget image = null)Sets the image of imagemenuitem to the given widget. Note that it depends on the show-menu-images setting whether the image will be displayed or not.void setUseStock(bool useStock)If true, the label set in the menuitem is used as a stock id to select the stock item for the item.T accelGroup(gtk.accel_group.AccelGroup propval)Set `accelGroup` property. Params: propval = The Accel Group to use for stock accelerator keys Returns: Builder instance for fluent chainingT alwaysShowImage(bool propval)Set `alwaysShowImage` property. Params: propval = If true, the menu item will always show the image, if available.T image(gtk.widget.Widget propval)Set `image` property. Params: propval = Child widget to appear next to the menu text. Returns: Builder instance for fluent chainingT useStock(bool propval)Set `useStock` property. Params: propval = If true, the label set in the menuitem is used as a stock id to select the stock item for the item. Returns: Builder instance for fluent chainingFluent builder for [gtk.image_menu_item.ImageMenuItem]