Synopsis
#include <gtk/gtk.h>
GtkLabel;
GtkWidget* gtk_label_new (const gchar *str);
void gtk_label_set_text (GtkLabel *label,
const gchar *str);
void gtk_label_set_attributes (GtkLabel *label,
PangoAttrList *attrs);
void gtk_label_set_markup (GtkLabel *label,
const gchar *str);
void gtk_label_set_markup_with_mnemonic (GtkLabel *label,
const gchar *str);
void gtk_label_set_pattern (GtkLabel *label,
const gchar *pattern);
void gtk_label_set_justify (GtkLabel *label,
GtkJustification jtype);
void gtk_label_set_ellipsize (GtkLabel *label,
PangoEllipsizeMode mode);
void gtk_label_set_width_chars (GtkLabel *label,
gint n_chars);
void gtk_label_set_max_width_chars (GtkLabel *label,
gint n_chars);
void gtk_label_get (GtkLabel *label,
gchar **str);
guint gtk_label_parse_uline (GtkLabel *label,
const gchar *string);
void gtk_label_set_line_wrap (GtkLabel *label,
gboolean wrap);
void gtk_label_set_line_wrap_mode (GtkLabel *label,
PangoWrapMode wrap_mode);
#define gtk_label_set
void gtk_label_get_layout_offsets (GtkLabel *label,
gint *x,
gint *y);
guint gtk_label_get_mnemonic_keyval (GtkLabel *label);
gboolean gtk_label_get_selectable (GtkLabel *label);
const gchar* gtk_label_get_text (GtkLabel *label);
GtkWidget* gtk_label_new_with_mnemonic (const gchar *str);
void gtk_label_select_region (GtkLabel *label,
gint start_offset,
gint end_offset);
void gtk_label_set_mnemonic_widget (GtkLabel *label,
GtkWidget *widget);
void gtk_label_set_selectable (GtkLabel *label,
gboolean setting);
void gtk_label_set_text_with_mnemonic (GtkLabel *label,
const gchar *str);
PangoAttrList* gtk_label_get_attributes (GtkLabel *label);
GtkJustification gtk_label_get_justify (GtkLabel *label);
PangoEllipsizeMode gtk_label_get_ellipsize (GtkLabel *label);
gint gtk_label_get_width_chars (GtkLabel *label);
gint gtk_label_get_max_width_chars (GtkLabel *label);
const gchar* gtk_label_get_label (GtkLabel *label);
PangoLayout* gtk_label_get_layout (GtkLabel *label);
gboolean gtk_label_get_line_wrap (GtkLabel *label);
PangoWrapMode gtk_label_get_line_wrap_mode (GtkLabel *label);
GtkWidget* gtk_label_get_mnemonic_widget (GtkLabel *label);
gboolean gtk_label_get_selection_bounds (GtkLabel *label,
gint *start,
gint *end);
gboolean gtk_label_get_use_markup (GtkLabel *label);
gboolean gtk_label_get_use_underline (GtkLabel *label);
gboolean gtk_label_get_single_line_mode (GtkLabel *label);
gdouble gtk_label_get_angle (GtkLabel *label);
void gtk_label_set_label (GtkLabel *label,
const gchar *str);
void gtk_label_set_use_markup (GtkLabel *label,
gboolean setting);
void gtk_label_set_use_underline (GtkLabel *label,
gboolean setting);
void gtk_label_set_single_line_mode (GtkLabel *label,
gboolean single_line_mode);
void gtk_label_set_angle (GtkLabel *label,
gdouble angle);
Object Hierarchy
GObject
+----GInitiallyUnowned
+----GtkObject
+----GtkWidget
+----GtkMisc
+----GtkLabel
+----GtkAccelLabel
+----GtkTipsQuery
Properties"angle" gdouble : Read / Write "attributes" PangoAttrList* : Read / Write "cursor-position" gint : Read "ellipsize" PangoEllipsizeMode : Read / Write "justify" GtkJustification : Read / Write "label" gchar* : Read / Write "max-width-chars" gint : Read / Write "mnemonic-keyval" guint : Read "mnemonic-widget" GtkWidget* : Read / Write "pattern" gchar* : Write "selectable" gboolean : Read / Write "selection-bound" gint : Read "single-line-mode" gboolean : Read / Write "use-markup" gboolean : Read / Write "use-underline" gboolean : Read / Write "width-chars" gint : Read / Write "wrap" gboolean : Read / Write "wrap-mode" PangoWrapMode : Read / Write Signals"copy-clipboard" : Run Last / Action "move-cursor" : Run Last / Action "populate-popup" : Run Last DescriptionThe GtkLabel widget displays a small amount of text. As the name implies, most labels are used to label another widget such as a GtkButton, a GtkMenuItem, or a GtkOptionMenu. GtkLabel as GtkBuildableThe GtkLabel implementation of the GtkBuildable interface supports a custom <attributes> element, which supports any number of <attribute> elements. the <attribute> element has attributes named name, value, start and end and allows you to specify PangoAttribute values for this label. Example 11. A UI definition fragment specifying Pango attributes
<object class="GtkLabel">
<attributes>
<attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
<attribute name="background" value="red" start="5" end="10"/>"
</attributes>
</object>
The start and end attributes specify the range of characters to which the Pango attribute applies. If start and end are not specified, the attribute is applied to the whole text. Note that specifying ranges does not make much sense with translatable attributes. Use markup embedded in the translatable content instead. Mnemonics
Labels may contain mnemonics. Mnemonics are
underlined characters in the label, used for keyboard navigation.
Mnemonics are created by providing a string with an underscore before
the mnemonic character, such as
Mnemonics automatically activate any activatable widget the label is
inside, such as a GtkButton; if the label is not inside the
mnemonic's target widget, you have to tell the label about the target
using
/* Pressing Alt+H will activate this button */
button = gtk_button_new ();
label = gtk_label_new_with_mnemonic ("_Hello");
gtk_container_add (GTK_CONTAINER (button), label);
There's a convenience function to create buttons with a mnemonic label already inside:
/* Pressing Alt+H will activate this button */
button = gtk_button_new_with_mnemonic ("_Hello");
To create a mnemonic for a widget alongside the label, such as a
GtkEntry, you have to point the label at the entry with
/* Pressing Alt+H will focus the entry */
entry = gtk_entry_new ();
label = gtk_label_new_with_mnemonic ("_Hello");
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
Markup (styled text)To make it easy to format text in a label (changing colors, fonts, etc.), label text can be provided in a simple markup format. Here's how to create a label with a small font: label = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>"); (See complete documentation of available tags in the Pango manual.)
The markup passed to
Markup strings are just a convenient way to set the PangoAttrList on
a label; Selectable labels
Labels can be made selectable with Text layoutA label can contain any number of paragraphs, but will have performance problems if it contains more than a small number. Paragraphs are separated by newlines or other paragraph separators understood by Pango.
Labels can automatically wrap text if you call
DetailsGtkLabeltypedef struct _GtkLabel GtkLabel; This should not be accessed directly. Use the accessor functions as described below. gtk_label_new ()GtkWidget* gtk_label_new (const gchar *str);
Creates a new label with the given text inside it. You can
pass
gtk_label_set_text ()void gtk_label_set_text (GtkLabel *label, const gchar *str); Sets the text within the GtkLabel widget. It overwrites any text that was there before. This will also clear any previously set mnemonic accelerators.
gtk_label_set_attributes ()void gtk_label_set_attributes (GtkLabel *label, PangoAttrList *attrs);
Sets a PangoAttrList; the attributes in the list are applied to the
label text. The attributes set with this function will be ignored
if the "use-underline"" or "use-markup" properties
are set to
gtk_label_set_markup ()void gtk_label_set_markup (GtkLabel *label, const gchar *str);
Parses
char *markup;
markup = g_markup_printf_escaped ("<span style=\"italic\">%s</span>", str);
gtk_label_set_markup (GTK_LABEL (label), markup);
g_free (markup);
gtk_label_set_markup_with_mnemonic ()void gtk_label_set_markup_with_mnemonic (GtkLabel *label, const gchar *str);
Parses
The mnemonic key can be used to activate another widget, chosen
automatically, or explicitly using
gtk_label_set_pattern ()void gtk_label_set_pattern (GtkLabel *label, const gchar *pattern); The pattern of underlines you want under the existing text within the GtkLabel widget. For example if the current text of the label says "FooBarBaz" passing a pattern of "___ ___" will underline "Foo" and "Baz" but not "Bar".
gtk_label_set_justify ()void gtk_label_set_justify (GtkLabel *label, GtkJustification jtype);
Sets the alignment of the lines in the text of the label relative to
each other.
gtk_label_set_ellipsize ()void gtk_label_set_ellipsize (GtkLabel *label, PangoEllipsizeMode mode); Sets the mode used to ellipsize (add an ellipsis: "...") to the text if there is not enough space to render the entire string.
Since 2.6 gtk_label_set_width_chars ()void gtk_label_set_width_chars (GtkLabel *label, gint n_chars);
Sets the desired width in characters of
Since 2.6 gtk_label_set_max_width_chars ()void gtk_label_set_max_width_chars (GtkLabel *label, gint n_chars);
Sets the desired maximum width in characters of
Since 2.6 gtk_label_get ()void gtk_label_get (GtkLabel *label, gchar **str); Warning
Gets the current string of text within the GtkLabel and writes it to
the given
gtk_label_parse_uline ()guint gtk_label_parse_uline (GtkLabel *label, const gchar *string); Warning
Parses the given string for underscores and converts the next character to an underlined character. The last character that was underlined will have its lower-cased accelerator keyval returned (i.e. "_File" would return the keyval for "f". This is probably only used within the GTK+ library itself for menu items and such.
gtk_label_set_line_wrap ()void gtk_label_set_line_wrap (GtkLabel *label, gboolean wrap);
Toggles line wrapping within the GtkLabel widget.
Note that setting line wrapping to
gtk_label_set_line_wrap_mode ()void gtk_label_set_line_wrap_mode (GtkLabel *label, PangoWrapMode wrap_mode);
If line wrapping is on (see
Since 2.10 gtk_label_set#define gtk_label_set gtk_label_set_text Warning
Aliases gtk_label_get_layout_offsets ()void gtk_label_get_layout_offsets (GtkLabel *label, gint *x, gint *y);
Obtains the coordinates where the label will draw the PangoLayout
representing the text in the label; useful to convert mouse events
into coordinates inside the PangoLayout, e.g. to take some action
if some part of the label is clicked. Of course you will need to
create a GtkEventBox to receive the events, and pack the label
inside it, since labels are a GTK_NO_WINDOW widget. Remember
when using the PangoLayout functions you need to convert to
and from pixels using
gtk_label_get_mnemonic_keyval ()guint gtk_label_get_mnemonic_keyval (GtkLabel *label); If the label has been set so that it has an mnemonic key this function returns the keyval used for the mnemonic accelerator. If there is no mnemonic set up it returns GDK_VoidSymbol.
gtk_label_get_selectable ()gboolean gtk_label_get_selectable (GtkLabel *label);
Gets the value set by
gtk_label_get_text ()const gchar* gtk_label_get_text (GtkLabel *label);
Fetches the text from a label widget, as displayed on the
screen. This does not include any embedded underlines
indicating mnemonics or Pango markup. (See
gtk_label_new_with_mnemonic ()GtkWidget* gtk_label_new_with_mnemonic (const gchar *str);
Creates a new GtkLabel, containing the text in
If characters in
If
gtk_label_select_region ()void gtk_label_select_region (GtkLabel *label, gint start_offset, gint end_offset);
Selects a range of characters in the label, if the label is selectable.
See
gtk_label_set_mnemonic_widget ()void gtk_label_set_mnemonic_widget (GtkLabel *label, GtkWidget *widget);
If the label has been set so that it has an mnemonic key (using
i.e. The target widget will be accelerated by emitting the GtkWidget::mnemonic-activate signal on it. The default handler for this signal will activate the widget if there are no mnemonic collisions and toggle focus between the colliding widgets otherwise.
gtk_label_set_selectable ()void gtk_label_set_selectable (GtkLabel *label, gboolean setting); Selectable labels allow the user to select text from the label, for copy-and-paste.
gtk_label_set_text_with_mnemonic ()void gtk_label_set_text_with_mnemonic (GtkLabel *label, const gchar *str);
Sets the label's text from the string
gtk_label_get_attributes ()PangoAttrList* gtk_label_get_attributes (GtkLabel *label);
Gets the attribute list that was set on the label using
gtk_label_get_justify ()GtkJustification gtk_label_get_justify (GtkLabel *label);
Returns the justification of the label. See
gtk_label_get_ellipsize ()PangoEllipsizeMode gtk_label_get_ellipsize (GtkLabel *label);
Returns the ellipsizing position of the label. See
Since 2.6 gtk_label_get_width_chars ()gint gtk_label_get_width_chars (GtkLabel *label);
Retrieves the desired width of
Since 2.6 gtk_label_get_max_width_chars ()gint gtk_label_get_max_width_chars (GtkLabel *label);
Retrieves the desired maximum width of
Since 2.6 gtk_label_get_label ()const gchar* gtk_label_get_label (GtkLabel *label);
Fetches the text from a label widget including any embedded
underlines indicating mnemonics and Pango markup. (See
gtk_label_get_layout ()PangoLayout* gtk_label_get_layout (GtkLabel *label);
Gets the PangoLayout used to display the label.
The layout is useful to e.g. convert text positions to
pixel positions, in combination with
gtk_label_get_line_wrap ()gboolean gtk_label_get_line_wrap (GtkLabel *label);
Returns whether lines in the label are automatically wrapped.
See
gtk_label_get_line_wrap_mode ()PangoWrapMode gtk_label_get_line_wrap_mode (GtkLabel *label);
Returns line wrap mode used by the label. See
Since 2.10 gtk_label_get_mnemonic_widget ()GtkWidget* gtk_label_get_mnemonic_widget (GtkLabel *label);
Retrieves the target of the mnemonic (keyboard shortcut) of this
label. See
gtk_label_get_selection_bounds ()gboolean gtk_label_get_selection_bounds (GtkLabel *label, gint *start, gint *end);
Gets the selected range of characters in the label, returning
gtk_label_get_use_markup ()gboolean gtk_label_get_use_markup (GtkLabel *label);
Returns whether the label's text is interpreted as marked up with
the Pango text markup
language. See
gtk_label_get_use_underline ()gboolean gtk_label_get_use_underline (GtkLabel *label);
Returns whether an embedded underline in the label indicates a
mnemonic. See
gtk_label_get_single_line_mode ()gboolean gtk_label_get_single_line_mode (GtkLabel *label); Returns whether the label is in single line mode.
Since 2.6 gtk_label_get_angle ()gdouble gtk_label_get_angle (GtkLabel *label);
Gets the angle of rotation for the label. See
Since 2.6 gtk_label_set_label ()void gtk_label_set_label (GtkLabel *label, const gchar *str); Sets the text of the label. The label is interpreted as including embedded underlines and/or Pango markup depending on the values of the "use-underline"" and "use-markup" properties.
gtk_label_set_use_markup ()void gtk_label_set_use_markup (GtkLabel *label, gboolean setting);
Sets whether the text of the label contains markup in Pango's text markup
language. See
gtk_label_set_use_underline ()void gtk_label_set_use_underline (GtkLabel *label, gboolean setting); If true, an underline in the text indicates the next character should be used for the mnemonic accelerator key.
gtk_label_set_single_line_mode ()void gtk_label_set_single_line_mode (GtkLabel *label, gboolean single_line_mode); Sets whether the label is in single line mode.
Since 2.6 gtk_label_set_angle ()void gtk_label_set_angle (GtkLabel *label, gdouble angle); Sets the angle of rotation for the label. An angle of 90 reads from from bottom to top, an angle of 270, from top to bottom. The angle setting for the label is ignored if the label is selectable, wrapped, or ellipsized.
Since 2.6 Property DetailsThe
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
the object which received the signal. |
|
user data set when the signal handler was connected. |
"move-cursor" signalvoid user_function (GtkLabel *label, GtkMovementStep arg1, gint arg2, gboolean arg3, gpointer user_data) : Run Last / Action
|
the object which received the signal. |
|
|
|
|
|
|
|
user data set when the signal handler was connected. |