AccelLabel


Object Hierarchy:

Gtk.AccelLabel Gtk.AccelLabel Gtk.AccelLabel Gtk.Label Gtk.Label Gtk.Label->Gtk.AccelLabel Gtk.Misc Gtk.Misc Gtk.Misc->Gtk.Label Gtk.Widget Gtk.Widget Gtk.Widget->Gtk.Misc GLib.InitiallyUnowned GLib.InitiallyUnowned GLib.InitiallyUnowned->Gtk.Widget GLib.Object GLib.Object GLib.Object->GLib.InitiallyUnowned Atk.Implementor Atk.Implementor Atk.Implementor->Gtk.AccelLabel Atk.Implementor->Gtk.Label Atk.Implementor->Gtk.Misc Atk.Implementor->Gtk.Widget Gtk.Buildable Gtk.Buildable Gtk.Buildable->Gtk.AccelLabel Gtk.Buildable->Gtk.Label Gtk.Buildable->Gtk.Misc Gtk.Buildable->Gtk.Widget

Description:

[ CCode ( type_id = "gtk_accel_label_get_type ()" ) ]
public class AccelLabel : Label, Implementor, Buildable

The AccelLabel widget is a subclass of Label 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 set_accel). Instead, the AccelLabel displays the accelerators which have been added to a particular widget. This widget is set by calling set_accel_widget.

For example, a MenuItem widget may have an accelerator added to emit the “activate” signal when the “Ctrl+S” key combination is pressed. A AccelLabel is created and added to the MenuItem, and set_accel_widget is called with the MenuItem as the second argument. The AccelLabel will now display “Ctrl+S” after its label.

Note that creating a MenuItem with MenuItem.with_label (or one of the similar functions for CheckMenuItem and RadioMenuItem) automatically adds a AccelLabel to the MenuItem and calls set_accel_widget to set it up for you.

A AccelLabel will only display accelerators which have gtk_accel_visible set (see AccelFlags). A AccelLabel 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
Label, GtkAccelLabel has a main CSS node with the name label. It adds a subnode with name accelerator.


Namespace: Gtk
Package: gtk+-3.0

Content:

Properties:

Creation methods:

Methods:

Inherited Members:

All known members inherited from class Gtk.Misc
All known members inherited from class Gtk.Widget
All known members inherited from interface Atk.Implementor