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 <!-- ##### STRUCT GtkLabel ##### -->
193 This should not be accessed directly. Use the accessor functions as
198 <!-- ##### SIGNAL GtkLabel::activate-current-link ##### -->
203 @label: the object which received the signal.
205 <!-- ##### SIGNAL GtkLabel::activate-link ##### -->
210 @label: the object which received the signal.
214 <!-- ##### SIGNAL GtkLabel::copy-clipboard ##### -->
219 @label: the object which received the signal.
221 <!-- ##### SIGNAL GtkLabel::move-cursor ##### -->
226 @label: the object which received the signal.
231 <!-- ##### SIGNAL GtkLabel::populate-popup ##### -->
236 @label: the object which received the signal.
239 <!-- ##### ARG GtkLabel:angle ##### -->
244 <!-- ##### ARG GtkLabel:attributes ##### -->
249 <!-- ##### ARG GtkLabel:cursor-position ##### -->
254 <!-- ##### ARG GtkLabel:ellipsize ##### -->
259 <!-- ##### ARG GtkLabel:justify ##### -->
264 <!-- ##### ARG GtkLabel:label ##### -->
269 <!-- ##### ARG GtkLabel:max-width-chars ##### -->
274 <!-- ##### ARG GtkLabel:mnemonic-keyval ##### -->
279 <!-- ##### ARG GtkLabel:mnemonic-widget ##### -->
284 <!-- ##### ARG GtkLabel:pattern ##### -->
289 <!-- ##### ARG GtkLabel:selectable ##### -->
294 <!-- ##### ARG GtkLabel:selection-bound ##### -->
299 <!-- ##### ARG GtkLabel:single-line-mode ##### -->
304 <!-- ##### ARG GtkLabel:track-visited-links ##### -->
309 <!-- ##### ARG GtkLabel:use-markup ##### -->
314 <!-- ##### ARG GtkLabel:use-underline ##### -->
319 <!-- ##### ARG GtkLabel:width-chars ##### -->
324 <!-- ##### ARG GtkLabel:wrap ##### -->
329 <!-- ##### ARG GtkLabel:wrap-mode ##### -->
334 <!-- ##### FUNCTION gtk_label_new ##### -->
343 <!-- ##### FUNCTION gtk_label_set_text ##### -->
352 <!-- ##### FUNCTION gtk_label_set_attributes ##### -->
361 <!-- ##### FUNCTION gtk_label_set_markup ##### -->
370 <!-- ##### FUNCTION gtk_label_set_markup_with_mnemonic ##### -->
379 <!-- ##### FUNCTION gtk_label_set_pattern ##### -->
381 The pattern of underlines you want under the existing text within the
382 #GtkLabel widget. For example if the current text of the label says
383 "FooBarBaz" passing a pattern of "___ ___" will underline
384 "Foo" and "Baz" but not "Bar".
387 @label: The #GtkLabel you want to set the pattern to.
388 @pattern: The pattern as described above.
391 <!-- ##### FUNCTION gtk_label_set_justify ##### -->
400 <!-- ##### FUNCTION gtk_label_set_ellipsize ##### -->
409 <!-- ##### FUNCTION gtk_label_set_width_chars ##### -->
418 <!-- ##### FUNCTION gtk_label_set_max_width_chars ##### -->
427 <!-- ##### FUNCTION gtk_label_get ##### -->
429 Gets the current string of text within the #GtkLabel and writes it to
430 the given @str argument. It does not make a copy of this string so you
431 must not write to it.
434 @label: The #GtkLabel widget you want to get the text from.
435 @str: The reference to the pointer you want to point to the text.
436 @Deprecated: Use gtk_label_get_text() instead.
439 <!-- ##### FUNCTION gtk_label_parse_uline ##### -->
441 Parses the given string for underscores and converts the next
442 character to an underlined character. The last character that
443 was underlined will have its lower-cased accelerator keyval returned (i.e.
444 "_File" would return the keyval for "f". This is
445 probably only used within the GTK+ library itself for menu items and such.
448 @label: The #GtkLabel you want to affect.
449 @string: The string you want to parse for underlines.
450 @Returns: The lowercase keyval of the last character underlined.
451 @Deprecated: Use gtk_label_set_use_underline() instead.
454 <!-- ##### FUNCTION gtk_label_set_line_wrap ##### -->
463 <!-- ##### FUNCTION gtk_label_set_line_wrap_mode ##### -->
472 <!-- ##### MACRO gtk_label_set ##### -->
474 Sets the text within the GtkLabel widget.
477 @Deprecated: Use gtk_label_set_text() instead.
480 <!-- ##### FUNCTION gtk_label_get_layout_offsets ##### -->
490 <!-- ##### FUNCTION gtk_label_get_mnemonic_keyval ##### -->
499 <!-- ##### FUNCTION gtk_label_get_selectable ##### -->
508 <!-- ##### FUNCTION gtk_label_get_text ##### -->
517 <!-- ##### FUNCTION gtk_label_new_with_mnemonic ##### -->
526 <!-- ##### FUNCTION gtk_label_select_region ##### -->
536 <!-- ##### FUNCTION gtk_label_set_mnemonic_widget ##### -->
545 <!-- ##### FUNCTION gtk_label_set_selectable ##### -->
554 <!-- ##### FUNCTION gtk_label_set_text_with_mnemonic ##### -->
563 <!-- ##### FUNCTION gtk_label_get_attributes ##### -->
572 <!-- ##### FUNCTION gtk_label_get_justify ##### -->
581 <!-- ##### FUNCTION gtk_label_get_ellipsize ##### -->
590 <!-- ##### FUNCTION gtk_label_get_width_chars ##### -->
599 <!-- ##### FUNCTION gtk_label_get_max_width_chars ##### -->
608 <!-- ##### FUNCTION gtk_label_get_label ##### -->
617 <!-- ##### FUNCTION gtk_label_get_layout ##### -->
626 <!-- ##### FUNCTION gtk_label_get_line_wrap ##### -->
635 <!-- ##### FUNCTION gtk_label_get_line_wrap_mode ##### -->
644 <!-- ##### FUNCTION gtk_label_get_mnemonic_widget ##### -->
653 <!-- ##### FUNCTION gtk_label_get_selection_bounds ##### -->
664 <!-- ##### FUNCTION gtk_label_get_use_markup ##### -->
673 <!-- ##### FUNCTION gtk_label_get_use_underline ##### -->
682 <!-- ##### FUNCTION gtk_label_get_single_line_mode ##### -->
691 <!-- ##### FUNCTION gtk_label_get_angle ##### -->
700 <!-- ##### FUNCTION gtk_label_set_label ##### -->
709 <!-- ##### FUNCTION gtk_label_set_use_markup ##### -->
718 <!-- ##### FUNCTION gtk_label_set_use_underline ##### -->
727 <!-- ##### FUNCTION gtk_label_set_single_line_mode ##### -->
736 <!-- ##### FUNCTION gtk_label_set_angle ##### -->
745 <!-- ##### FUNCTION gtk_label_get_current_uri ##### -->
754 <!-- ##### FUNCTION gtk_label_set_track_visited_links ##### -->
763 <!-- ##### FUNCTION gtk_label_get_track_visited_links ##### -->