1
<!-- ##### SECTION Title ##### -->
4
<!-- ##### SECTION Short_Description ##### -->
5
A widget that displays a small to medium amount of text
7
<!-- ##### SECTION Long_Description ##### -->
9
The #GtkLabel widget displays a small amount of text. As the name
10
implies, most labels are used to label another widget such as a
11
#GtkButton, a #GtkMenuItem, or a #GtkOptionMenu.
14
<refsect2 id="GtkLabel-BUILDER-UI">
15
<title>GtkLabel as GtkBuildable</title>
17
The GtkLabel implementation of the GtkBuildable interface supports a
18
custom <attributes> element, which supports any number of <attribute>
19
elements. the <attribute> element has attributes named name, value,
20
start and end and allows you to specify #PangoAttribute values for this label.
23
<title>A UI definition fragment specifying Pango attributes</title>
24
<programlisting><![CDATA[
25
<object class="GtkLabel">
27
<attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
28
<attribute name="background" value="red" start="5" end="10"/>"
34
The start and end attributes specify the range of characters to which the
35
Pango attribute applies. If start and end are not specified, the attribute is
36
applied to the whole text. Note that specifying ranges does not make much
37
sense with translatable attributes. Use markup embedded in the translatable
44
<title>Mnemonics</title>
47
Labels may contain <firstterm>mnemonics</firstterm>. Mnemonics are
48
underlined characters in the label, used for keyboard navigation.
49
Mnemonics are created by providing a string with an underscore before
50
the mnemonic character, such as <literal>"_File"</literal>, to the
51
functions gtk_label_new_with_mnemonic() or
52
gtk_label_set_text_with_mnemonic().
56
Mnemonics automatically activate any activatable widget the label is
57
inside, such as a #GtkButton; if the label is not inside the
58
mnemonic's target widget, you have to tell the label about the target
59
using gtk_label_set_mnemonic_widget(). Here's a simple example where
60
the label is inside a button:
64
/* Pressing Alt+H will activate this button */
65
button = gtk_button_new (<!-- -->);
66
label = gtk_label_new_with_mnemonic ("_Hello");
67
gtk_container_add (GTK_CONTAINER (button), label);
70
There's a convenience function to create buttons with a mnemonic label
75
/* Pressing Alt+H will activate this button */
76
button = gtk_button_new_with_mnemonic ("_Hello");
80
To create a mnemonic for a widget alongside the label, such as a
81
#GtkEntry, you have to point the label at the entry with
82
gtk_label_set_mnemonic_widget():
85
/* Pressing Alt+H will focus the entry */
86
entry = gtk_entry_new (<!-- -->);
87
label = gtk_label_new_with_mnemonic ("_Hello");
88
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
97
<title>Markup (styled text)</title>
100
To make it easy to format text in a label (changing colors, fonts,
101
etc.), label text can be provided in a simple <link
102
linkend="PangoMarkupFormat">markup format</link>.
103
Here's how to create a label with a small font:
106
label = gtk_label_new (NULL);
107
gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>");
111
linkend="PangoMarkupFormat">complete documentation</link> of available
112
tags in the Pango manual.)
115
The markup passed to gtk_label_set_markup() must be valid; for example,
116
literal </>/& characters must be escaped as &lt;,
117
&gt;, and &amp;. If you pass text obtained from the user, file,
118
or a network to gtk_label_set_markup(), you'll want to escape it with
119
g_markup_escape_text() or g_markup_printf_escaped().
122
Markup strings are just a convenient way to set the #PangoAttrList on
123
a label; gtk_label_set_attributes() may be a simpler way to set
124
attributes in some cases. Be careful though; #PangoAttrList tends to
125
cause internationalization problems, unless you're applying attributes
126
to the entire string (i.e. unless you set the range of each attribute
127
to [0, G_MAXINT)). The reason is that specifying the start_index and
128
end_index for a #PangoAttribute requires knowledge of the exact string
129
being displayed, so translations will cause problems.
134
<title>Selectable labels</title>
137
Labels can be made selectable with gtk_label_set_selectable().
138
Selectable labels allow the user to copy the label contents to
139
the clipboard. Only labels that contain useful-to-copy information
140
— such as error messages — should be made selectable.
145
<title>Text layout</title>
148
A label can contain any number of paragraphs, but will have
149
performance problems if it contains more than a small number.
150
Paragraphs are separated by newlines or other paragraph separators
154
Labels can automatically wrap text if you call
155
gtk_label_set_line_wrap().
158
gtk_label_set_justify() sets how the lines in a label align
159
with one another. If you want to set how the label as a whole
160
aligns in its available space, see gtk_misc_set_alignment().
169
Since 2.18, GTK+ supports markup for clickable hyperlinks in addition
170
to regular Pango markup. The markup for links is borrowed from HTML, using the
171
<tag>a</tag> with href and title attributes. GTK+ renders links similar to the
172
way they appear in web browsers, with colored, underlined text. The title
173
attribute is displayed as a tooltip on the link. An example looks like this:
174
<informalexample><programlisting>
175
gtk_label_set_markup (label, "Go to the <a href=\"http://www.gtk.org\" title=\"&lt;i&gt;Our&/i&gt; website\">GTK+ website</a> for more...");
176
</programlisting></informalexample>
177
It is possible to implement custom handling for links and their tooltips with
178
the #GtkLabel::activate-link signal and the gtk_label_get_current_uri() function.
183
<!-- ##### SECTION See_Also ##### -->
188
<!-- ##### SECTION Stability_Level ##### -->
191
<!-- ##### SECTION Image ##### -->
194
<!-- ##### STRUCT GtkLabel ##### -->
196
This should not be accessed directly. Use the accessor functions as
201
<!-- ##### SIGNAL GtkLabel::activate-current-link ##### -->
206
@label: the object which received the signal.
208
<!-- ##### SIGNAL GtkLabel::activate-link ##### -->
213
@label: the object which received the signal.
217
<!-- ##### SIGNAL GtkLabel::copy-clipboard ##### -->
222
@label: the object which received the signal.
224
<!-- ##### SIGNAL GtkLabel::move-cursor ##### -->
229
@label: the object which received the signal.
234
<!-- ##### SIGNAL GtkLabel::populate-popup ##### -->
239
@label: the object which received the signal.
242
<!-- ##### ARG GtkLabel:angle ##### -->
247
<!-- ##### ARG GtkLabel:attributes ##### -->
252
<!-- ##### ARG GtkLabel:cursor-position ##### -->
257
<!-- ##### ARG GtkLabel:ellipsize ##### -->
262
<!-- ##### ARG GtkLabel:justify ##### -->
267
<!-- ##### ARG GtkLabel:label ##### -->
272
<!-- ##### ARG GtkLabel:max-width-chars ##### -->
277
<!-- ##### ARG GtkLabel:mnemonic-keyval ##### -->
282
<!-- ##### ARG GtkLabel:mnemonic-widget ##### -->
287
<!-- ##### ARG GtkLabel:pattern ##### -->
292
<!-- ##### ARG GtkLabel:selectable ##### -->
297
<!-- ##### ARG GtkLabel:selection-bound ##### -->
302
<!-- ##### ARG GtkLabel:single-line-mode ##### -->
307
<!-- ##### ARG GtkLabel:track-visited-links ##### -->
312
<!-- ##### ARG GtkLabel:use-markup ##### -->
317
<!-- ##### ARG GtkLabel:use-underline ##### -->
322
<!-- ##### ARG GtkLabel:width-chars ##### -->
327
<!-- ##### ARG GtkLabel:wrap ##### -->
332
<!-- ##### ARG GtkLabel:wrap-mode ##### -->
337
<!-- ##### FUNCTION gtk_label_new ##### -->
346
<!-- ##### FUNCTION gtk_label_set_text ##### -->
355
<!-- ##### FUNCTION gtk_label_set_attributes ##### -->
364
<!-- ##### FUNCTION gtk_label_set_markup ##### -->
373
<!-- ##### FUNCTION gtk_label_set_markup_with_mnemonic ##### -->
382
<!-- ##### FUNCTION gtk_label_set_pattern ##### -->
384
The pattern of underlines you want under the existing text within the
385
#GtkLabel widget. For example if the current text of the label says
386
"FooBarBaz" passing a pattern of "___ ___" will underline
387
"Foo" and "Baz" but not "Bar".
390
@label: The #GtkLabel you want to set the pattern to.
391
@pattern: The pattern as described above.
394
<!-- ##### FUNCTION gtk_label_set_justify ##### -->
403
<!-- ##### FUNCTION gtk_label_set_ellipsize ##### -->
412
<!-- ##### FUNCTION gtk_label_set_width_chars ##### -->
421
<!-- ##### FUNCTION gtk_label_set_max_width_chars ##### -->
430
<!-- ##### FUNCTION gtk_label_get ##### -->
432
Gets the current string of text within the #GtkLabel and writes it to
433
the given @str argument. It does not make a copy of this string so you
434
must not write to it.
437
@label: The #GtkLabel widget you want to get the text from.
438
@str: The reference to the pointer you want to point to the text.
439
@Deprecated: Use gtk_label_get_text() instead.
442
<!-- ##### FUNCTION gtk_label_parse_uline ##### -->
444
Parses the given string for underscores and converts the next
445
character to an underlined character. The last character that
446
was underlined will have its lower-cased accelerator keyval returned (i.e.
447
"_File" would return the keyval for "f". This is
448
probably only used within the GTK+ library itself for menu items and such.
451
@label: The #GtkLabel you want to affect.
452
@string: The string you want to parse for underlines.
453
@Returns: The lowercase keyval of the last character underlined.
454
@Deprecated: Use gtk_label_set_use_underline() instead.
457
<!-- ##### FUNCTION gtk_label_set_line_wrap ##### -->
466
<!-- ##### FUNCTION gtk_label_set_line_wrap_mode ##### -->
475
<!-- ##### MACRO gtk_label_set ##### -->
477
Sets the text within the GtkLabel widget.
480
@Deprecated: Use gtk_label_set_text() instead.
483
<!-- ##### FUNCTION gtk_label_get_layout_offsets ##### -->
493
<!-- ##### FUNCTION gtk_label_get_mnemonic_keyval ##### -->
502
<!-- ##### FUNCTION gtk_label_get_selectable ##### -->
511
<!-- ##### FUNCTION gtk_label_get_text ##### -->
520
<!-- ##### FUNCTION gtk_label_new_with_mnemonic ##### -->
529
<!-- ##### FUNCTION gtk_label_select_region ##### -->
539
<!-- ##### FUNCTION gtk_label_set_mnemonic_widget ##### -->
548
<!-- ##### FUNCTION gtk_label_set_selectable ##### -->
557
<!-- ##### FUNCTION gtk_label_set_text_with_mnemonic ##### -->
566
<!-- ##### FUNCTION gtk_label_get_attributes ##### -->
575
<!-- ##### FUNCTION gtk_label_get_justify ##### -->
584
<!-- ##### FUNCTION gtk_label_get_ellipsize ##### -->
593
<!-- ##### FUNCTION gtk_label_get_width_chars ##### -->
602
<!-- ##### FUNCTION gtk_label_get_max_width_chars ##### -->
611
<!-- ##### FUNCTION gtk_label_get_label ##### -->
620
<!-- ##### FUNCTION gtk_label_get_layout ##### -->
629
<!-- ##### FUNCTION gtk_label_get_line_wrap ##### -->
638
<!-- ##### FUNCTION gtk_label_get_line_wrap_mode ##### -->
647
<!-- ##### FUNCTION gtk_label_get_mnemonic_widget ##### -->
656
<!-- ##### FUNCTION gtk_label_get_selection_bounds ##### -->
667
<!-- ##### FUNCTION gtk_label_get_use_markup ##### -->
676
<!-- ##### FUNCTION gtk_label_get_use_underline ##### -->
685
<!-- ##### FUNCTION gtk_label_get_single_line_mode ##### -->
694
<!-- ##### FUNCTION gtk_label_get_angle ##### -->
703
<!-- ##### FUNCTION gtk_label_set_label ##### -->
712
<!-- ##### FUNCTION gtk_label_set_use_markup ##### -->
721
<!-- ##### FUNCTION gtk_label_set_use_underline ##### -->
730
<!-- ##### FUNCTION gtk_label_set_single_line_mode ##### -->
739
<!-- ##### FUNCTION gtk_label_set_angle ##### -->
748
<!-- ##### FUNCTION gtk_label_get_current_uri ##### -->
757
<!-- ##### FUNCTION gtk_label_set_track_visited_links ##### -->
766
<!-- ##### FUNCTION gtk_label_get_track_visited_links ##### -->