GtkAccelLabel — A label which displays an accelerator key on the right of the text
| GtkWidget * | gtk_accel_label_new () |
| void | gtk_accel_label_set_accel_closure () |
| GtkWidget * | gtk_accel_label_get_accel_widget () |
| void | gtk_accel_label_set_accel_widget () |
| guint | gtk_accel_label_get_accel_width () |
| void | gtk_accel_label_set_accel () |
| void | gtk_accel_label_get_accel () |
| gboolean | gtk_accel_label_refetch () |
| GClosure * | accel-closure | Read / Write |
| GtkWidget * | accel-widget | Read / Write |
| struct | GtkAccelLabel |
GObject
╰── GInitiallyUnowned
╰── GtkWidget
╰── GtkMisc
╰── GtkLabel
╰── GtkAccelLabel
GtkAccelLabel implements AtkImplementorIface and GtkBuildable.
#include <gtk/gtk.h>
The GtkAccelLabel widget is a subclass of GtkLabel that also displays an accelerator key on the right of the label text, e.g. “Ctrl+S”. It is commonly used in menus to show the keyboard short-cuts for commands.
The accelerator key to display is typically not set explicitly (although it can be, with gtk_accel_label_set_accel()). Instead, the GtkAccelLabel displays the accelerators which have been added to a particular widget. This widget is set by calling gtk_accel_label_set_accel_widget().
For example, a GtkMenuItem widget may have an accelerator added to emit the “activate” signal when the “Ctrl+S” key combination is pressed. A GtkAccelLabel is created and added to the GtkMenuItem, and gtk_accel_label_set_accel_widget() is called with the GtkMenuItem as the second argument. The GtkAccelLabel will now display “Ctrl+S” after its label.
Note that creating a GtkMenuItem with gtk_menu_item_new_with_label() (or one of the similar functions for GtkCheckMenuItem and GtkRadioMenuItem) automatically adds a GtkAccelLabel to the GtkMenuItem and calls gtk_accel_label_set_accel_widget() to set it up for you.
A GtkAccelLabel will only display accelerators which have GTK_ACCEL_VISIBLE set (see GtkAccelFlags). A GtkAccelLabel can display multiple accelerators and even signal names, though it is almost always used to display just one accelerator key.
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
GtkWidget *menu = gtk_menu_new ();
GtkWidget *save_item;
GtkAccelGroup *accel_group;
// Create a GtkAccelGroup and add it to the window.
accel_group = gtk_accel_group_new ();
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
// Create the menu item using the convenience function.
save_item = gtk_menu_item_new_with_label ("Save");
gtk_widget_show (save_item);
gtk_container_add (GTK_CONTAINER (menu), save_item);
// Now add the accelerator to the GtkMenuItem. Note that since we
// called gtk_menu_item_new_with_label() to create the GtkMenuItem
// the GtkAccelLabel is automatically set up to display the
// GtkMenuItem accelerators. We just need to make sure we use
// GTK_ACCEL_VISIBLE here.
gtk_widget_add_accelerator (save_item, "activate", accel_group,
GDK_KEY_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);Like GtkLabel, GtkAccelLabel has a main CSS node with the name label. It adds a subnode with name accelerator.
GtkWidget *
gtk_accel_label_new (const gchar *string); Creates a new GtkAccelLabel.
string | the label string. Must be non- |
a new GtkAccelLabel.
void gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,GClosure *accel_closure);
Sets the closure to be monitored by this accelerator label. The closure must be connected to an accelerator group; see gtk_accel_group_connect(). Passing NULL for accel_closure will dissociate accel_label from its current closure, if any.
accel_label | ||
accel_closure | the closure to monitor for accelerator changes, or | [nullable] |
GtkWidget *
gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label); Fetches the widget monitored by this accelerator label. See gtk_accel_label_set_accel_widget().
accel_label |
the object monitored by the accelerator label, or NULL.
[nullable][transfer none]
void gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,GtkWidget *accel_widget);
Sets the widget to be monitored by this accelerator label. Passing NULL for accel_widget will dissociate accel_label from its current widget, if any.
accel_label | ||
accel_widget | the widget to be monitored, or | [nullable] |
guint
gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label); Returns the width needed to display the accelerator key(s). This is used by menus to align all of the GtkMenuItem widgets, and shouldn't be needed by applications.
accel_label |
the width needed to display the accelerator key(s).
void gtk_accel_label_set_accel (GtkAccelLabel *accel_label,guint accelerator_key,GdkModifierType accelerator_mods);
Manually sets a keyval and modifier mask as the accelerator rendered by accel_label .
If a keyval and modifier are explicitly set then these values are used regardless of any associated accel closure or widget.
Providing an accelerator_key of 0 removes the manual setting.
accel_label | ||
accelerator_key | a keyval, or 0 | |
accelerator_mods | the modifier mask for the accel |
Since: 3.6
void gtk_accel_label_get_accel (GtkAccelLabel *accel_label,guint *accelerator_key,GdkModifierType *accelerator_mods);
Gets the keyval and modifier mask set with gtk_accel_label_set_accel().
accel_label | ||
accelerator_key | return location for the keyval. | [out] |
accelerator_mods | return location for the modifier mask. | [out] |
Since: 3.12
gboolean
gtk_accel_label_refetch (GtkAccelLabel *accel_label); Recreates the string representing the accelerator keys. This should not be needed since the string is automatically updated whenever accelerators are added or removed from the associated widget.
accel_label |
always returns FALSE.
struct GtkAccelLabel;
The GtkAccelLabel contains private data only, and should be accessed using the functions below.
“accel-closure” property“accel-closure” GClosure *
The closure to be monitored for accelerator changes.
Owner: GtkAccelLabel
Flags: Read / Write
“accel-widget” property“accel-widget” GtkWidget *
The widget to be monitored for accelerator changes.
Owner: GtkAccelLabel
Flags: Read / Write
© 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/GtkAccelLabel.html