ImageMenuItem

open class ImageMenuItem : MenuItem, ImageMenuItemProtocol

A GtkImageMenuItem is a menu item which has an icon next to the text label.

This is functionally equivalent to:

(C Language Example):

  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. 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_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:

(C Language Example):

  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);

The ImageMenuItem type acts as a reference-counted owner of an underlying GtkImageMenuItem instance. It provides the methods that can operate on this data type through ImageMenuItemProtocol conformance. Use ImageMenuItem as a strong reference or owner of a GtkImageMenuItem instance.

  • Designated initialiser from the underlying `C` data type.
    

    This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the ImageMenuItem instance.

    Declaration

    Swift

    @inlinable
    public init(_ op: UnsafeMutablePointer<GtkImageMenuItem>)

    Parameters

    op

    pointer to the underlying object

  • Designated initialiser from a constant pointer to the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the ImageMenuItem instance.

    Declaration

    Swift

    @inlinable
    public init(_ op: UnsafePointer<GtkImageMenuItem>)

    Parameters

    op

    pointer to the underlying object

  • Optional initialiser from a non-mutating gpointer to the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the ImageMenuItem instance.

    Declaration

    Swift

    @inlinable
    override public init!(gpointer op: gpointer?)

    Parameters

    op

    gpointer to the underlying object

  • Optional initialiser from a non-mutating gconstpointer to the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the ImageMenuItem instance.

    Declaration

    Swift

    @inlinable
    override public init!(gconstpointer op: gconstpointer?)

    Parameters

    op

    pointer to the underlying object

  • Optional initialiser from a constant pointer to the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the ImageMenuItem instance.

    Declaration

    Swift

    @inlinable
    public init!(_ op: UnsafePointer<GtkImageMenuItem>?)

    Parameters

    op

    pointer to the underlying object

  • Optional initialiser from the underlying C data type. This creates an instance without performing an unbalanced retain i.e., ownership is transferred to the ImageMenuItem instance.

    Declaration

    Swift

    @inlinable
    public init!(_ op: UnsafeMutablePointer<GtkImageMenuItem>?)

    Parameters

    op

    pointer to the underlying object

  • Designated initialiser from the underlying C data type. Will retain GtkImageMenuItem. i.e., ownership is transferred to the ImageMenuItem instance.

    Declaration

    Swift

    @inlinable
    public init(retaining op: UnsafeMutablePointer<GtkImageMenuItem>)

    Parameters

    op

    pointer to the underlying object

  • Reference intialiser for a related type that implements ImageMenuItemProtocol Will retain GtkImageMenuItem.

    Declaration

    Swift

    @inlinable
    public init<T>(imageMenuItem other: T) where T : ImageMenuItemProtocol

    Parameters

    other

    an instance of a related type that implements ImageMenuItemProtocol

  • Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ImageMenuItemProtocol.

    Declaration

    Swift

    @inlinable
    override public init<T>(cPointer p: UnsafeMutablePointer<T>)

    Parameters

    cPointer

    pointer to the underlying object

  • Unsafe typed, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ImageMenuItemProtocol.

    Declaration

    Swift

    @inlinable
    override public init<T>(retainingCPointer cPointer: UnsafeMutablePointer<T>)

    Parameters

    cPointer

    pointer to the underlying object

  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ImageMenuItemProtocol.

    Declaration

    Swift

    @inlinable
    override public init(raw p: UnsafeRawPointer)

    Parameters

    p

    raw pointer to the underlying object

  • Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ImageMenuItemProtocol.

    Declaration

    Swift

    @inlinable
    override public init(retainingRaw raw: UnsafeRawPointer)
  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ImageMenuItemProtocol.

    Declaration

    Swift

    @inlinable
    public required init(raw p: UnsafeMutableRawPointer)

    Parameters

    p

    mutable raw pointer to the underlying object

  • Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ImageMenuItemProtocol.

    Declaration

    Swift

    @inlinable
    required public init(retainingRaw raw: UnsafeMutableRawPointer)

    Parameters

    raw

    mutable raw pointer to the underlying object

  • Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ImageMenuItemProtocol.

    Declaration

    Swift

    @inlinable
    override public init(opaquePointer p: OpaquePointer)

    Parameters

    p

    opaque pointer to the underlying object

  • Unsafe untyped, retaining initialiser. Do not use unless you know the underlying data type the pointer points to conforms to ImageMenuItemProtocol.

    Declaration

    Swift

    @inlinable
    override public init(retainingOpaquePointer p: OpaquePointer)

    Parameters

    p

    opaque pointer to the underlying object

  • Creates a new GtkImageMenuItem with an empty label.

    new is deprecated: Use gtk_menu_item_new() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    override public init()
  • Creates a new GtkImageMenuItem containing the image and text from a stock item. Some stock ids have preprocessor macros like GTK_STOCK_OK and GTK_STOCK_APPLY.

    If you want this menu item to have changeable accelerators, then pass in nil for accel_group. Next call gtk_menu_item_set_accel_path() with an appropriate path for the menu item, use gtk_stock_lookup() to look up the standard accelerator for the stock item, and if one is found, call gtk_accel_map_add_entry() to register it.

    new_from_stock is deprecated: Use gtk_menu_item_new_with_mnemonic() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    public init<AccelGroupT>(stock stockID: UnsafePointer<gchar>!, accelGroup: AccelGroupT?) where AccelGroupT : AccelGroupProtocol
  • Creates a new GtkImageMenuItem containing a label.

    new_with_label is deprecated: Use gtk_menu_item_new_with_label() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    override public init(label: UnsafePointer<gchar>!)
  • Creates a new GtkImageMenuItem containing a label. The label will be created using gtk_label_new_with_mnemonic(), so underscores in label indicate the mnemonic for the menu item.

    new_with_mnemonic is deprecated: Use gtk_menu_item_new_with_mnemonic() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    override public init(mnemonic label: UnsafePointer<gchar>!)
  • Creates a new GtkImageMenuItem containing the image and text from a stock item. Some stock ids have preprocessor macros like GTK_STOCK_OK and GTK_STOCK_APPLY.

    If you want this menu item to have changeable accelerators, then pass in nil for accel_group. Next call gtk_menu_item_set_accel_path() with an appropriate path for the menu item, use gtk_stock_lookup() to look up the standard accelerator for the stock item, and if one is found, call gtk_accel_map_add_entry() to register it.

    new_from_stock is deprecated: Use gtk_menu_item_new_with_mnemonic() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    public static func newFrom<AccelGroupT>(stock stockID: UnsafePointer<gchar>!, accelGroup: AccelGroupT?) -> Widget! where AccelGroupT : AccelGroupProtocol
  • Creates a new GtkImageMenuItem containing a label.

    new_with_label is deprecated: Use gtk_menu_item_new_with_label() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    public static func imageMenuItemNewWith(label: UnsafePointer<gchar>!) -> Widget!
  • Creates a new GtkImageMenuItem containing a label. The label will be created using gtk_label_new_with_mnemonic(), so underscores in label indicate the mnemonic for the menu item.

    new_with_mnemonic is deprecated: Use gtk_menu_item_new_with_mnemonic() instead.

    Declaration

    Swift

    @available(*, deprecated)
    @inlinable
    public static func imageMenuItemNewWith(mnemonic label: UnsafePointer<gchar>!) -> Widget!