Package: gtk

Class gtk:image-menu-item

Superclasses

Documented Subclasses

None

Direct Slots

accel-group
The accel-group property of type gtk:accel-group (Write)
The accelerator group to use for stock accelerator keys.
always-show-image
The always-show-image property of type :boolean (Read / Write / Construct)
If true, the menu item will ignore the gtk-menu-images setting and always show the image, if available.
Default value: false
image
The image property of type gtk:widget (Read / Write)
Child widget to appear next to the menu text.
use-stock
The use-stock property of type :boolean (Read / Write / Construct)
If true, the label set in the menu item is used as a stock ID to select the stock item for the item.
Default value: false

Details

The gtk:image-menu-item widget is a menu item which has an icon next to the text label. This is functionally equivalent to:
(defun create-image-menu-item ()
  (let ((box (make-instance 'gtk:box
                            :orientation :horizontal
                            :spacing 6))
        (icon (make-instance 'gtk:image
                             :icon-name "folder-music-symbolic"
                             :icon-size 1))
        (label (make-instance 'gtk:label
                              :label "Music"))
        (menuitem (make-instance 'gtk:menu-item)))
    (gtk:container-add box icon)
    (gtk:container-add box label)
    (gtk:container-add menuitem box)
    menuitem))  
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 gtk:menu-item widget with a gtk:image widget instead.

Furthermore, if you would like to display keyboard accelerator, you must pack the accel label into the box using the gtk:box-pack-end function 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 the Ctrl+M key:
(defun create-image-menu-item-with-accel ()
  (let ((box (make-instance 'gtk:box
                            :orientation :horizontal
                            :spacing 6))
        (icon (make-instance 'gtk:image
                             :icon-name "folder-music-symbolic"
                             :icon-size 1))
        (label (make-instance 'gtk:accel-label
                              :label "Music"
                              :use-underline t
                              :xalign 0.0))
        (menuitem (make-instance 'gtk:menu-item))
        (accel-group (make-instance 'gtk:accel-group)))
    (gtk:widget-add-accelerator menuitem
                                "activate"
                                accel-group
                                (gdk-keyval-from-name "M")
                                :control-mask
                                :visible)
    (setf (gtk:accel-label-accel-widget label) menuitem)
    (gtk:container-add box icon)
    (gtk:box-pack-end box label :expand t :fill t :padding 0)
    (gtk:container-add menuitem box)
    menuitem))  

Warning

The gtk:image-menu-item class has been deprecated since GTK 3.10. If you want to display an icon in a menu item, you should use the gtk:menu-item widget and pack a gtk:box widget with a gtk:image widget and a gtk:label widget instead. You should also consider using the gtk:builder object and the g:menu XML description for creating menus, by following the g:menu 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.
 

Returned by

Slot Access Functions

Inherited Slot Access Functions

See also

2024-6-27