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 #PangoAttributs 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\"/>
36 <title>Mnemonics</title>
39 Labels may contain <firstterm>mnemonics</firstterm>. Mnemonics are
40 underlined characters in the label, used for keyboard navigation.
41 Mnemonics are created by providing a string with an underscore before
42 the mnemonic character, such as <literal>"_File"</literal>, to the
43 functions gtk_label_new_with_mnemonic() or
44 gtk_label_set_text_with_mnemonic().
48 Mnemonics automatically activate any activatable widget the label is
49 inside, such as a #GtkButton; if the label is not inside the
50 mnemonic's target widget, you have to tell the label about the target
51 using gtk_label_set_mnemonic_widget(). Here's a simple example where
52 the label is inside a button:
56 /* Pressing Alt+H will activate this button */
57 button = gtk_button_new (<!-- -->);
58 label = gtk_label_new_with_mnemonic ("_Hello");
59 gtk_container_add (GTK_CONTAINER (button), label);
62 There's a convenience function to create buttons with a mnemonic label
67 /* Pressing Alt+H will activate this button */
68 button = gtk_button_new_with_mnemonic ("_Hello");
72 To create a mnemonic for a widget alongside the label, such as a
73 #GtkEntry, you have to point the label at the entry with
74 gtk_label_set_mnemonic_widget():
77 /* Pressing Alt+H will focus the entry */
78 entry = gtk_entry_new (<!-- -->);
79 label = gtk_label_new_with_mnemonic ("_Hello");
80 gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
89 <title>Markup (styled text)</title>
92 To make it easy to format text in a label (changing colors, fonts,
93 etc.), label text can be provided in a simple <link
94 linkend="PangoMarkupFormat">markup format</link>.
95 Here's how to create a label with a small font:
98 label = gtk_label_new (NULL);
99 gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>");
103 linkend="PangoMarkupFormat">complete documentation</link> of available
104 tags in the Pango manual.)
107 The markup passed to gtk_label_set_markup() must be valid; for example,
108 literal </>/& characters must be escaped as &lt;,
109 &gt;, and &amp;. If you pass text obtained from the user, file,
110 or a network to gtk_label_set_markup(), you'll want to escape it with
111 g_markup_escape_text() or g_markup_printf_escaped().
114 Markup strings are just a convenient way to set the #PangoAttrList on
115 a label; gtk_label_set_attributes() may be a simpler way to set
116 attributes in some cases. Be careful though; #PangoAttrList tends to
117 cause internationalization problems, unless you're applying attributes
118 to the entire string (i.e. unless you set the range of each attribute
119 to [0, G_MAXINT)). The reason is that specifying the start_index and
120 end_index for a #PangoAttribute requires knowledge of the exact string
121 being displayed, so translations will cause problems.
126 <title>Selectable labels</title>
129 Labels can be made selectable with gtk_label_set_selectable().
130 Selectable labels allow the user to copy the label contents to
131 the clipboard. Only labels that contain useful-to-copy information
132 — such as error messages — should be made selectable.
137 <title>Text layout</title>
140 A label can contain any number of paragraphs, but will have
141 performance problems if it contains more than a small number.
142 Paragraphs are separated by newlines or other paragraph separators
146 Labels can automatically wrap text if you call
147 gtk_label_set_line_wrap().
150 gtk_label_set_justify() sets how the lines in a label align
151 with one another. If you want to set how the label as a whole
152 aligns in its available space, see gtk_misc_set_alignment().
157 <!-- ##### SECTION See_Also ##### -->
162 <!-- ##### SECTION Stability_Level ##### -->
165 <!-- ##### STRUCT GtkLabel ##### -->
167 This should not be accessed directly. Use the accessor functions as
172 <!-- ##### SIGNAL GtkLabel::copy-clipboard ##### -->
177 @label: the object which received the signal.
179 <!-- ##### SIGNAL GtkLabel::move-cursor ##### -->
184 @label: the object which received the signal.
189 <!-- ##### SIGNAL GtkLabel::populate-popup ##### -->
194 @label: the object which received the signal.
197 <!-- ##### ARG GtkLabel:angle ##### -->
202 <!-- ##### ARG GtkLabel:attributes ##### -->
207 <!-- ##### ARG GtkLabel:cursor-position ##### -->
212 <!-- ##### ARG GtkLabel:ellipsize ##### -->
217 <!-- ##### ARG GtkLabel:justify ##### -->
222 <!-- ##### ARG GtkLabel:label ##### -->
227 <!-- ##### ARG GtkLabel:max-width-chars ##### -->
232 <!-- ##### ARG GtkLabel:mnemonic-keyval ##### -->
237 <!-- ##### ARG GtkLabel:mnemonic-widget ##### -->
242 <!-- ##### ARG GtkLabel:pattern ##### -->
247 <!-- ##### ARG GtkLabel:selectable ##### -->
252 <!-- ##### ARG GtkLabel:selection-bound ##### -->
257 <!-- ##### ARG GtkLabel:single-line-mode ##### -->
262 <!-- ##### ARG GtkLabel:use-markup ##### -->
267 <!-- ##### ARG GtkLabel:use-underline ##### -->
272 <!-- ##### ARG GtkLabel:width-chars ##### -->
277 <!-- ##### ARG GtkLabel:wrap ##### -->
282 <!-- ##### ARG GtkLabel:wrap-mode ##### -->
287 <!-- ##### FUNCTION gtk_label_new ##### -->
296 <!-- ##### FUNCTION gtk_label_set_text ##### -->
305 <!-- ##### FUNCTION gtk_label_set_attributes ##### -->
314 <!-- ##### FUNCTION gtk_label_set_markup ##### -->
323 <!-- ##### FUNCTION gtk_label_set_markup_with_mnemonic ##### -->
332 <!-- ##### FUNCTION gtk_label_set_pattern ##### -->
334 The pattern of underlines you want under the existing text within the
335 #GtkLabel widget. For example if the current text of the label says
336 "FooBarBaz" passing a pattern of "___ ___" will underline
337 "Foo" and "Baz" but not "Bar".
340 @label: The #GtkLabel you want to set the pattern to.
341 @pattern: The pattern as described above.
344 <!-- ##### FUNCTION gtk_label_set_justify ##### -->
353 <!-- ##### FUNCTION gtk_label_set_ellipsize ##### -->
362 <!-- ##### FUNCTION gtk_label_set_width_chars ##### -->
371 <!-- ##### FUNCTION gtk_label_set_max_width_chars ##### -->
380 <!-- ##### FUNCTION gtk_label_get ##### -->
382 Gets the current string of text within the #GtkLabel and writes it to
383 the given @str argument. It does not make a copy of this string so you
384 must not write to it.
387 @label: The #GtkLabel widget you want to get the text from.
388 @str: The reference to the pointer you want to point to the text.
391 <!-- ##### FUNCTION gtk_label_parse_uline ##### -->
393 Parses the given string for underscores and converts the next
394 character to an underlined character. The last character that
395 was underlined will have its lower-cased accelerator keyval returned (i.e.
396 "_File" would return the keyval for "f". This is
397 probably only used within the GTK+ library itself for menu items and such.
400 @label: The #GtkLabel you want to affect.
401 @string: The string you want to parse for underlines.
402 @Returns: The lowercase keyval of the last character underlined.
405 <!-- ##### FUNCTION gtk_label_set_line_wrap ##### -->
414 <!-- ##### FUNCTION gtk_label_set_line_wrap_mode ##### -->
423 <!-- ##### MACRO gtk_label_set ##### -->
425 Aliases gtk_label_set_text(). Probably used for backward compatibility with
431 <!-- ##### FUNCTION gtk_label_get_layout_offsets ##### -->
441 <!-- ##### FUNCTION gtk_label_get_mnemonic_keyval ##### -->
450 <!-- ##### FUNCTION gtk_label_get_selectable ##### -->
459 <!-- ##### FUNCTION gtk_label_get_text ##### -->
468 <!-- ##### FUNCTION gtk_label_new_with_mnemonic ##### -->
477 <!-- ##### FUNCTION gtk_label_select_region ##### -->
487 <!-- ##### FUNCTION gtk_label_set_mnemonic_widget ##### -->
496 <!-- ##### FUNCTION gtk_label_set_selectable ##### -->
505 <!-- ##### FUNCTION gtk_label_set_text_with_mnemonic ##### -->
514 <!-- ##### FUNCTION gtk_label_get_attributes ##### -->
523 <!-- ##### FUNCTION gtk_label_get_justify ##### -->
532 <!-- ##### FUNCTION gtk_label_get_ellipsize ##### -->
541 <!-- ##### FUNCTION gtk_label_get_width_chars ##### -->
550 <!-- ##### FUNCTION gtk_label_get_max_width_chars ##### -->
559 <!-- ##### FUNCTION gtk_label_get_label ##### -->
568 <!-- ##### FUNCTION gtk_label_get_layout ##### -->
577 <!-- ##### FUNCTION gtk_label_get_line_wrap ##### -->
586 <!-- ##### FUNCTION gtk_label_get_line_wrap_mode ##### -->
595 <!-- ##### FUNCTION gtk_label_get_mnemonic_widget ##### -->
604 <!-- ##### FUNCTION gtk_label_get_selection_bounds ##### -->
615 <!-- ##### FUNCTION gtk_label_get_use_markup ##### -->
624 <!-- ##### FUNCTION gtk_label_get_use_underline ##### -->
633 <!-- ##### FUNCTION gtk_label_get_single_line_mode ##### -->
642 <!-- ##### FUNCTION gtk_label_get_angle ##### -->
651 <!-- ##### FUNCTION gtk_label_set_label ##### -->
660 <!-- ##### FUNCTION gtk_label_set_use_markup ##### -->
669 <!-- ##### FUNCTION gtk_label_set_use_underline ##### -->
678 <!-- ##### FUNCTION gtk_label_set_single_line_mode ##### -->
687 <!-- ##### FUNCTION gtk_label_set_angle ##### -->