Object Hierarchy:

Object hierarchy for ImageMenuItem


[ Version ( deprecated = true , deprecated_since = "3.10" ) ]
public class ImageMenuItem : MenuItem, Implementor, Actionable, Activatable, Buildable

Warning: ImageMenuItem is deprecated since "3.10".

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 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 MenuItem with a Image instead.

ImageMenuItem has been deprecated since GTK+ 3.10. If you want to display an icon in a menu item, you should use MenuItem and pack a Box with a Image and a Label instead. You should also consider using Builder and the XML Menu description for creating menus, by following the [GMenu guide][]. 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 pack_end 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,
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);

Example: ImageMenuItem:

public class Application : Gtk.Window {
public Application () {
// Prepare Gtk.Window:
this.title = "My Gtk.ImageMenuItem";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);

// MenuBar:
Gtk.MenuBar bar = new Gtk.MenuBar ();
this.add (bar);

// File:
Gtk.MenuItem item_file = new Gtk.MenuItem.with_label ("File");
bar.add (item_file);

Gtk.Menu filemenu = new Gtk.Menu ();
item_file.set_submenu (filemenu);

Gtk.ImageMenuItem item_open = new Gtk.ImageMenuItem.with_label ("Open");
Gtk.Image image = new Gtk.Image.from_icon_name ("document-open", Gtk.IconSize.MENU);
item_open.always_show_image = true;
item_open.set_image (image);

item_open.activate.connect (() => {
Gtk.FileChooserDialog chooser = new Gtk.FileChooserDialog (
"Select your favorite file", this, Gtk.FileChooserAction.OPEN,
Gtk.ResponseType.ACCEPT); ();
chooser.close ();
filemenu.add (item_open);

public static int main (string[] args) {
Gtk.init (ref args);

Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;

valac --pkg gtk+-3.0 Gtk.ImageMenuItem.vala

Namespace: Gtk
Package: gtk+-3.0



Creation methods:


Inherited Members:

All known members inherited from class Gtk.Bin
All known members inherited from class Gtk.Widget
All known members inherited from interface Atk.Implementor