gtk.accel_label

Module for [AccelLabel] class

Types 3

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.AccelLabel.setAccel]). Instead, the #GtkAccelLabel displays the accelerators which have been added to a particular widget. This widget is set by calling [gtk.accel_label.AccelLabel.setAccelWidget].

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.AccelLabel.setAccelWidget] 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.MenuItem.newWithLabel] (or one of the similar functions for #GtkCheckMenuItem and #GtkRadioMenuItem) automatically adds a #GtkAccelLabel to the #GtkMenuItem and calls [gtk.accel_label.AccelLabel.setAccelWidget] to set it up for you.

A #GtkAccelLabel will only display accelerators which have [gtk.types.AccelFlags.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.

Creating a simple menu item with an 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);

CSS nodes

label
╰── accelerator

Like #GtkLabel, GtkAccelLabel has a main CSS node with the name label. It adds a subnode with name accelerator.

Methods
GType _gType() @property
AccelLabel self()Returns `this`, for use in `with` statements.
AccelLabelGidBuilder builder()Get builder for [gtk.accel_label.AccelLabel] Returns: New builder object
void accelClosure(gobject.closure.Closure propval) @property
void accelWidget(gtk.widget.Widget propval) @property
void getAccel(out uint acceleratorKey, out gdk.types.ModifierType acceleratorMods)Gets the keyval and modifier mask set with [gtk.accel_label.AccelLabel.setAccel].
gtk.widget.Widget getAccelWidget()Fetches the widget monitored by this accelerator label. See [gtk.accel_label.AccelLabel.setAccelWidget]. Returns: the object monitored by the accelerator label, or null.
uint getAccelWidth()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. Returns: the width needed to dis...
bool refetch()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. Re...
void setAccel(uint acceleratorKey, gdk.types.ModifierType acceleratorMods)Manually sets a keyval and modifier mask as the accelerator rendered by accel_label.
void setAccelClosure(gobject.closure.Closure accelClosure = null)Sets the closure to be monitored by this accelerator label. The closure must be connected to an accelerator group; see [gtk.accelgroup.AccelGroup.connect]. Passing null for accelclosure will dissoc...
void setAccelWidget(gtk.widget.Widget accelWidget = null)Sets the widget to be monitored by this accelerator label. Passing null for accelwidget will dissociate accellabel from its current widget, if any.
Constructors
this(void * ptr, Flag!"Take" take)
this(string string_)Creates a new #GtkAccelLabel.

Fluent builder for [gtk.accel_label.AccelLabel]

Methods