GtkMenuItem — The widget used for item in menus
GtkWidget * | gtk_menu_item_new () |
GtkWidget * | gtk_menu_item_new_with_label () |
GtkWidget * | gtk_menu_item_new_with_mnemonic () |
void | gtk_menu_item_set_right_justified () |
gboolean | gtk_menu_item_get_right_justified () |
const gchar * | gtk_menu_item_get_label () |
void | gtk_menu_item_set_label () |
gboolean | gtk_menu_item_get_use_underline () |
void | gtk_menu_item_set_use_underline () |
void | gtk_menu_item_set_submenu () |
GtkWidget * | gtk_menu_item_get_submenu () |
void | gtk_menu_item_set_accel_path () |
const gchar * | gtk_menu_item_get_accel_path () |
void | gtk_menu_item_select () |
void | gtk_menu_item_deselect () |
void | gtk_menu_item_activate () |
void | gtk_menu_item_toggle_size_request () |
void | gtk_menu_item_toggle_size_allocate () |
gboolean | gtk_menu_item_get_reserve_indicator () |
void | gtk_menu_item_set_reserve_indicator () |
char * | accel-path | Read / Write |
char * | label | Read / Write |
gboolean | right-justified | Read / Write |
GtkMenu * | submenu | Read / Write |
gboolean | use-underline | Read / Write |
float | arrow-scaling | Read |
int | arrow-spacing | Read |
int | horizontal-padding | Read |
GtkShadowType | selected-shadow-type | Read |
int | toggle-spacing | Read |
int | width-chars | Read |
void | activate | Action |
void | activate-item | Run First |
void | deselect | Run First |
void | select | Run First |
void | toggle-size-allocate | Run First |
void | toggle-size-request | Run First |
struct | GtkMenuItem |
struct | GtkMenuItemClass |
GObject ╰── GInitiallyUnowned ╰── GtkWidget ╰── GtkContainer ╰── GtkBin ╰── GtkMenuItem ├── GtkCheckMenuItem ├── GtkImageMenuItem ├── GtkSeparatorMenuItem ╰── GtkTearoffMenuItem
GtkMenuItem implements AtkImplementorIface, GtkBuildable, GtkActivatable and GtkActionable.
#include <gtk/gtk.h>
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:
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:
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 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.
GtkWidget *
gtk_menu_item_new (void
);
Creates a new GtkMenuItem.
the newly created GtkMenuItem
GtkWidget *
gtk_menu_item_new_with_label (const gchar *label
);
Creates a new GtkMenuItem whose child is a GtkLabel.
label | the text for the label |
the newly created GtkMenuItem
GtkWidget *
gtk_menu_item_new_with_mnemonic (const gchar *label
);
Creates a new GtkMenuItem 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.
label | The text of the button, with an underscore in front of the mnemonic character |
a new GtkMenuItem
void gtk_menu_item_set_right_justified (GtkMenuItem *menu_item
,gboolean right_justified
);
gtk_menu_item_set_right_justified
has been deprecated since version 3.2 and should not be used in newly-written code.
If you insist on using it, use gtk_widget_set_hexpand()
and gtk_widget_set_halign()
.
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 reversed for a right-to-left language like Hebrew or Arabic, right-justified-menu-items appear at the left.)
menu_item | a GtkMenuItem. | |
right_justified | if |
gboolean
gtk_menu_item_get_right_justified (GtkMenuItem *menu_item
);
gtk_menu_item_get_right_justified
has been deprecated since version 3.2 and should not be used in newly-written code.
Gets whether the menu item appears justified at the right side of the menu bar.
menu_item |
TRUE
if the menu item will appear at the far right if added to a menu bar.
const gchar *
gtk_menu_item_get_label (GtkMenuItem *menu_item
);
Sets text
on the menu_item
label
menu_item |
The text in the menu_item
label. This is the internal string used by the label, and must not be modified.
Since: 2.16
void gtk_menu_item_set_label (GtkMenuItem *menu_item
,const gchar *label
);
Sets text
on the menu_item
label
menu_item | ||
label | the text you want to set |
Since: 2.16
gboolean
gtk_menu_item_get_use_underline (GtkMenuItem *menu_item
);
Checks if an underline in the text indicates the next character should be used for the mnemonic accelerator key.
menu_item |
TRUE
if an embedded underline in the label indicates the mnemonic accelerator key.
Since: 2.16
void gtk_menu_item_set_use_underline (GtkMenuItem *menu_item
,gboolean setting
);
If true, an underline in the text indicates the next character should be used for the mnemonic accelerator key.
menu_item | ||
setting |
|
Since: 2.16
void gtk_menu_item_set_submenu (GtkMenuItem *menu_item
,GtkWidget *submenu
);
Sets or replaces the menu item’s submenu, or removes it when a NULL
submenu is passed.
menu_item | ||
submenu | the submenu, or | [allow-none][type Gtk.Menu] |
GtkWidget *
gtk_menu_item_get_submenu (GtkMenuItem *menu_item
);
Gets the submenu underneath this menu item, if any. See gtk_menu_item_set_submenu()
.
menu_item |
submenu for this menu item, or NULL
if none.
[nullable][transfer none]
void gtk_menu_item_set_accel_path (GtkMenuItem *menu_item
,const gchar *accel_path
);
Set the accelerator path on menu_item
, through which runtime changes of the menu item’s accelerator caused by the user can be identified and saved to persistent storage (see gtk_accel_map_save()
on this). To set up a default accelerator for this menu item, call gtk_accel_map_add_entry()
with the same accel_path
. See also gtk_accel_map_add_entry()
on the specifics of accelerator paths, and gtk_menu_set_accel_path()
for a more convenient variant of this function.
This function is basically a convenience wrapper that handles calling gtk_widget_set_accel_path()
with the appropriate accelerator group for the menu item.
Note that you do need to set an accelerator on the parent menu with gtk_menu_set_accel_group()
for this to work.
Note that accel_path
string will be stored in a GQuark. Therefore, if you pass a static string, you can save some memory by interning it first with g_intern_static_string()
.
menu_item | a valid GtkMenuItem | |
accel_path | accelerator path, corresponding to this menu item’s functionality, or | [allow-none] |
const gchar *
gtk_menu_item_get_accel_path (GtkMenuItem *menu_item
);
Retrieve the accelerator path that was previously set on menu_item
.
See gtk_menu_item_set_accel_path()
for details.
menu_item | a valid GtkMenuItem |
the accelerator path corresponding to this menu item’s functionality, or NULL
if not set.
[nullable][transfer none]
Since: 2.14
void
gtk_menu_item_select (GtkMenuItem *menu_item
);
Emits the “select” signal on the given item.
menu_item | the menu item |
void
gtk_menu_item_deselect (GtkMenuItem *menu_item
);
Emits the “deselect” signal on the given item.
menu_item | the menu item |
void
gtk_menu_item_activate (GtkMenuItem *menu_item
);
Emits the “activate” signal on the given item
menu_item | the menu item |
void gtk_menu_item_toggle_size_request (GtkMenuItem *menu_item
,gint *requisition
);
Emits the “toggle-size-request” signal on the given item.
menu_item | the menu item | |
requisition | the requisition to use as signal data. | [inout] |
void gtk_menu_item_toggle_size_allocate (GtkMenuItem *menu_item
,gint allocation
);
Emits the “toggle-size-allocate” signal on the given item.
menu_item | the menu item. | |
allocation | the allocation to use as signal data. |
gboolean
gtk_menu_item_get_reserve_indicator (GtkMenuItem *menu_item
);
Returns whether the menu_item
reserves space for the submenu indicator, regardless if it has a submenu or not.
menu_item |
TRUE
if menu_item
always reserves space for the submenu indicator
Since: 3.0
void gtk_menu_item_set_reserve_indicator (GtkMenuItem *menu_item
,gboolean reserve
);
Sets whether the menu_item
should reserve space for the submenu indicator, regardless if it actually has a submenu or not.
There should be little need for applications to call this functions.
menu_item | ||
reserve | the new value |
Since: 3.0
struct GtkMenuItem;
struct GtkMenuItemClass { GtkBinClass parent_class; /* If the following flag is true, then we should always * hide the menu when the MenuItem is activated. Otherwise, * it is up to the caller. For instance, when navigating * a menu with the keyboard, <Space> doesn't hide, but * <Return> does. */ guint hide_on_activate : 1; void (* activate) (GtkMenuItem *menu_item); void (* activate_item) (GtkMenuItem *menu_item); void (* toggle_size_request) (GtkMenuItem *menu_item, gint *requisition); void (* toggle_size_allocate) (GtkMenuItem *menu_item, gint allocation); void (* set_label) (GtkMenuItem *menu_item, const gchar *label); const gchar * (* get_label) (GtkMenuItem *menu_item); void (* select) (GtkMenuItem *menu_item); void (* deselect) (GtkMenuItem *menu_item); };
guint | If | |
| Signal emitted when the item is activated. | |
| Signal emitted when the item is activated, but also if the menu item has a submenu. | |
| ||
| ||
| Sets | |
| Gets | |
| Signal emitted when the item is selected. | |
| Signal emitted when the item is deselected. |
“accel-path”
property“accel-path” char *
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 persistant storage.
Owner: GtkMenuItem
Flags: Read / Write
Default value: NULL
Since: 2.14
“label”
property“label” char *
The text for the child label.
Owner: GtkMenuItem
Flags: Read / Write
Default value: ""
Since: 2.16
“right-justified”
property“right-justified” gboolean
Sets whether the menu item appears justified at the right side of a menu bar.
Owner: GtkMenuItem
Flags: Read / Write
Default value: FALSE
Since: 2.14
“submenu”
property“submenu” GtkMenu *
The submenu attached to the menu item, or NULL
if it has none.
Owner: GtkMenuItem
Flags: Read / Write
Since: 2.12
“use-underline”
property“use-underline” gboolean
TRUE
if underlines in the text indicate mnemonics.
Owner: GtkMenuItem
Flags: Read / Write
Default value: FALSE
Since: 2.16
“arrow-scaling”
style property“arrow-scaling” float
Amount of space used up by the arrow, relative to the menu item's font size.
GtkMenuItem:arrow-scaling
has been deprecated since version 3.20 and should not be used in newly-written code.
use the standard min-width/min-height CSS properties on the arrow node; the value of this style property is ignored.
Owner: GtkMenuItem
Flags: Read
Allowed values: [0,2]
Default value: 0.8
“arrow-spacing”
style property“arrow-spacing” int
Spacing between menu item label and submenu arrow.
GtkMenuItem:arrow-spacing
has been deprecated since version 3.20 and should not be used in newly-written code.
use the standard margin CSS property on the arrow node; the value of this style property is ignored.
Owner: GtkMenuItem
Flags: Read
Allowed values: >= 0
Default value: 10
“horizontal-padding”
style property“horizontal-padding” int
Padding to left and right of the menu item.
GtkMenuItem:horizontal-padding
has been deprecated since version 3.8 and should not be used in newly-written code.
use the standard padding CSS property (through objects like GtkStyleContext and GtkCssProvider); the value of this style property is ignored.
Owner: GtkMenuItem
Flags: Read
Allowed values: >= 0
Default value: 0
“selected-shadow-type”
style property“selected-shadow-type” GtkShadowType
The shadow type when the item is selected.
GtkMenuItem:selected-shadow-type
has been deprecated since version 3.20 and should not be used in newly-written code.
Use CSS to determine the shadow; the value of this style property is ignored.
Owner: GtkMenuItem
Flags: Read
Default value: GTK_SHADOW_NONE
“toggle-spacing”
style property“toggle-spacing” int
Spacing between menu icon and label.
GtkMenuItem:toggle-spacing
has been deprecated since version 3.20 and should not be used in newly-written code.
use the standard margin CSS property on the check or radio nodes; the value of this style property is ignored.
Owner: GtkMenuItem
Flags: Read
Allowed values: >= 0
Default value: 5
“width-chars”
style property“width-chars” int
The minimum desired width of the menu item in characters.
GtkMenuItem:width-chars
has been deprecated since version 3.20 and should not be used in newly-written code.
Use the standard CSS property min-width; the value of this style property is ignored.
Owner: GtkMenuItem
Flags: Read
Allowed values: >= 0
Default value: 12
Since: 2.14
“activate”
signalvoid user_function (GtkMenuItem *menuitem, gpointer user_data)
Emitted when the item is activated.
menuitem | the object which received the signal. | |
user_data | user data set when the signal handler was connected. |
Flags: Action
“activate-item”
signalvoid user_function (GtkMenuItem *menuitem, gpointer user_data)
Emitted when the item is activated, but also if the menu item has a submenu. For normal applications, the relevant signal is “activate”.
menuitem | the object which received the signal. | |
user_data | user data set when the signal handler was connected. |
Flags: Run First
“deselect”
signalvoid user_function (GtkMenuItem *menuitem, gpointer user_data)
Flags: Run First
“toggle-size-allocate”
signalvoid user_function (GtkMenuItem *menuitem, int arg1, gpointer user_data)
Flags: Run First
“toggle-size-request”
signalvoid user_function (GtkMenuItem *menuitem, gpointer arg1, gpointer user_data)
Flags: Run First
© 2005–2020 The GNOME Project
Licensed under the GNU Lesser General Public License version 2.1 or later.
https://developer.gnome.org/gtk3/3.24/GtkMenuItem.html