GtkAccelLabel

GtkAccelLabel — A label which displays an accelerator key on the right of the text

Properties

gchar * label Read / Write
gboolean use-underline Read / Write

Types and Values

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── GtkWidget
            ╰── GtkAccelLabel

Implemented Interfaces

GtkAccelLabel implements AtkImplementorIface, GtkBuildable and GtkConstraintTarget.

Includes

#include <gtk/gtk.h>

Description

The GtkAccelLabel is a widget that shows an accelerator next to a description of said accelerator, e.g. “Save Document 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 menu item 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 menu item widget, and gtk_accel_label_set_accel_widget() is called with the item as the second argument. The GtkAccelLabel will now display “Ctrl+S” after its label.

Note that accel labels are typically set up automatically when menus are created.

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.

CSS nodes

1
2
3
accellabel
  ├── label
  ╰── accelerator

GtkAccelLabel has a main CSS node with the name accellabel. It contains the two child nodes with name label and accelerator.

Functions

gtk_accel_label_new ()

GtkWidget *
gtk_accel_label_new (const gchar *string);

Creates a new GtkAccelLabel.

Parameters

string

the label string. Must be non-NULL.

 

Returns

a new GtkAccelLabel.


gtk_accel_label_get_accel_width ()

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 menu item widgets, and shouldn't be needed by applications.

Parameters

accel_label

a GtkAccelLabel.

 

Returns

the width needed to display the accelerator key(s).


gtk_accel_label_set_accel ()

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.

Parameters

accel_label

a GtkAccelLabel

 

accelerator_key

a keyval, or 0

 

accelerator_mods

the modifier mask for the accel

 

gtk_accel_label_get_accel ()

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().

Parameters

accel_label

a GtkAccelLabel

 

accelerator_key

return location for the keyval.

[out]

accelerator_mods

return location for the modifier mask.

[out]

gtk_accel_label_refetch ()

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.

Parameters

accel_label

a GtkAccelLabel.

 

Returns

always returns FALSE.


gtk_accel_label_set_label ()

void
gtk_accel_label_set_label (GtkAccelLabel *accel_label,
                           const char *text);

Sets the label part of the accel label.

Parameters

accel_label

a GtkAccelLabel

 

text

The new label text

 

gtk_accel_label_get_label ()

const char *
gtk_accel_label_get_label (GtkAccelLabel *accel_label);

Returns the current label, set via gtk_accel_label_set_label()

Parameters

accel_label

a GtkAccelLabel

 

Returns

accel_label 's label.

[transfer none]


gtk_accel_label_get_use_underline ()

gboolean
gtk_accel_label_get_use_underline (GtkAccelLabel *accel_label);

Returns whether the accel label interprets underscores in it's label property as mnemonic indicators. See gtk_accel_label_set_use_underline() and gtk_label_set_use_underline();

Parameters

accel_label

a GtkAccelLabel

 

Returns

whether the accel label uses mnemonic underlines


gtk_accel_label_set_use_underline ()

void
gtk_accel_label_set_use_underline (GtkAccelLabel *accel_label,
                                   gboolean setting);

Controls whether to interpret underscores in the text label of accel_label as mnemonic indicators. See also gtk_label_set_use_underline()

Parameters

accel_label

a GtkAccelLabel

 

setting

Whether to use underlines in the label or not

 

Types and Values

GtkAccelLabel

typedef struct _GtkAccelLabel GtkAccelLabel;

Property Details

The “label” property

  “label”                    gchar *

The text displayed next to the accelerator.

Owner: GtkAccelLabel

Flags: Read / Write

Default value: ""


The “use-underline” property

  “use-underline”            gboolean

If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key.

Owner: GtkAccelLabel

Flags: Read / Write

Default value: FALSE

See Also

GtkAccelGroup