![]() |
![]() |
![]() |
GTK+ 3 Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
#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_set_line_wrap (GtkLabel *label
,gboolean wrap
); void gtk_label_set_line_wrap_mode (GtkLabel *label
,PangoWrapMode wrap_mode
); 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
); const gchar * gtk_label_get_current_uri (GtkLabel *label
); void gtk_label_set_track_visited_links (GtkLabel *label
,gboolean track_links
); gboolean gtk_label_get_track_visited_links (GtkLabel *label
);
GtkWidget* gtk_label_new (const gchar *str
);
Creates a new label with the given text inside it. You can
pass NULL
to get an empty label widget.
|
The text of the label |
Returns : |
the new GtkLabel |
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.
|
a GtkLabel |
|
The text you want to set |
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 applied and merged with any other attributes previously effected by way of the "use-underline" or "use-markup" properties. While it is not recommended to mix markup strings with manually set attributes, if you must; know that the attributes will be applied to the label after the markup string is parsed.
|
a GtkLabel |
|
a PangoAttrList |
void gtk_label_set_markup (GtkLabel *label
,const gchar *str
);
Parses str
which is marked up with the Pango text markup language, setting the
label's text and attribute list based on the parse results. If the str
is
external data, you may need to escape it with g_markup_escape_text()
or
g_markup_printf_escaped()
:
1 2 3 4 5 |
char *markup; markup = g_markup_printf_escaped ("<span style=\"italic\">%s</span>", str); gtk_label_set_markup (GTK_LABEL (label), markup); g_free (markup); |
|
a GtkLabel |
|
a markup string (see Pango markup format) |
void gtk_label_set_markup_with_mnemonic (GtkLabel *label
,const gchar *str
);
Parses str
which is marked up with the
Pango text markup language,
setting the label's text and attribute list based on the parse results.
If characters in str
are preceded by an underscore, they are underlined
indicating that they represent a keyboard accelerator called a mnemonic.
The mnemonic key can be used to activate another widget, chosen
automatically, or explicitly using gtk_label_set_mnemonic_widget()
.
|
a GtkLabel |
|
a markup string (see Pango markup format) |
void gtk_label_set_pattern (GtkLabel *label
,const gchar *pattern
);
|
|
|
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_JUSTIFY_LEFT
is the default value when the
widget is first created with gtk_label_new()
. If you instead want
to set the alignment of the label as a whole, use
gtk_misc_set_alignment()
instead. gtk_label_set_justify()
has no
effect on labels containing only a single line.
|
a GtkLabel |
|
a GtkJustification |
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.
|
a GtkLabel |
|
a PangoEllipsizeMode |
Since 2.6
void gtk_label_set_width_chars (GtkLabel *label
,gint n_chars
);
Sets the desired width in characters of label
to n_chars
.
|
a GtkLabel |
|
the new desired width, in characters. |
Since 2.6
void gtk_label_set_max_width_chars (GtkLabel *label
,gint n_chars
);
Sets the desired maximum width in characters of label
to n_chars
.
|
a GtkLabel |
|
the new desired maximum width, in characters. |
Since 2.6
void gtk_label_set_line_wrap (GtkLabel *label
,gboolean wrap
);
Toggles line wrapping within the GtkLabel widget. TRUE
makes it break
lines if text exceeds the widget's size. FALSE
lets the text get cut off
by the edge of the widget if it exceeds the widget size.
Note that setting line wrapping to TRUE
does not make the label
wrap at its parent container's width, because GTK+ widgets
conceptually can't make their requisition depend on the parent
container's size. For a label that wraps at a specific position,
set the label's width using gtk_widget_set_size_request()
.
|
a GtkLabel |
|
the setting |
void gtk_label_set_line_wrap_mode (GtkLabel *label
,PangoWrapMode wrap_mode
);
If line wrapping is on (see gtk_label_set_line_wrap()
) this controls how
the line wrapping is done. The default is PANGO_WRAP_WORD
which means
wrap on word boundaries.
|
a GtkLabel |
|
the line wrapping mode |
Since 2.10
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 PANGO_PIXELS()
or PANGO_SCALE.
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.
|
a GtkLabel |
Returns : |
GDK keyval usable for accelerators, or GDK_VoidSymbol |
gboolean gtk_label_get_selectable (GtkLabel *label
);
Gets the value set by gtk_label_set_selectable()
.
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_get_label()
)
|
a GtkLabel |
Returns : |
the text in the label widget. This is the internal string used by the label, and must not be modified. |
GtkWidget* gtk_label_new_with_mnemonic (const gchar *str
);
Creates a new GtkLabel, containing the text in str
.
If characters in str
are preceded by an underscore, they are
underlined. If you need a literal underscore character in a label, use
'__' (two underscores). The first underlined character represents a
keyboard accelerator called a mnemonic. The mnemonic key can be used
to activate another widget, chosen automatically, or explicitly using
gtk_label_set_mnemonic_widget()
.
If gtk_label_set_mnemonic_widget()
is not called, then the first
activatable ancestor of the GtkLabel will be chosen as the mnemonic
widget. For instance, if the label is inside a button or menu item,
the button or menu item will automatically become the mnemonic widget
and be activated by the mnemonic.
|
The text of the label, with an underscore in front of the mnemonic character |
Returns : |
the new GtkLabel |
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_selectable()
. If the label is not selectable,
this function has no effect. If start_offset
or
end_offset
are -1, then the end of the label will be substituted.
|
a GtkLabel |
|
start offset (in characters not bytes) |
|
end offset (in characters not bytes) |
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. gtk_label_set_markup_with_mnemonic()
,
gtk_label_set_text_with_mnemonic()
, gtk_label_new_with_mnemonic()
or the "use_underline" property) the label can be associated with a
widget that is the target of the mnemonic. When the label is inside
a widget (like a GtkButton or a GtkNotebook tab) it is
automatically associated with the correct widget, but sometimes
(i.e. when the target is a GtkEntry next to the label) you need to
set it explicitly using this function.
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.
void gtk_label_set_selectable (GtkLabel *label
,gboolean setting
);
Selectable labels allow the user to select text from the label, for copy-and-paste.
void gtk_label_set_text_with_mnemonic (GtkLabel *label
,const gchar *str
);
Sets the label's text from the string str
.
If characters in str
are preceded by an underscore, they are underlined
indicating that they represent a keyboard accelerator called a mnemonic.
The mnemonic key can be used to activate another widget, chosen
automatically, or explicitly using gtk_label_set_mnemonic_widget()
.
|
a GtkLabel |
|
a string |
PangoAttrList * gtk_label_get_attributes (GtkLabel *label
);
Gets the attribute list that was set on the label using
gtk_label_set_attributes()
, if any. This function does
not reflect attributes that come from the labels markup
(see gtk_label_set_markup()
). If you want to get the
effective attributes for the label, use
pango_layout_get_attribute (gtk_label_get_layout (label)).
GtkJustification gtk_label_get_justify (GtkLabel *label
);
Returns the justification of the label. See gtk_label_set_justify()
.
|
a GtkLabel |
Returns : |
GtkJustification |
PangoEllipsizeMode gtk_label_get_ellipsize (GtkLabel *label
);
Returns the ellipsizing position of the label. See gtk_label_set_ellipsize()
.
|
a GtkLabel |
Returns : |
PangoEllipsizeMode |
Since 2.6
gint gtk_label_get_width_chars (GtkLabel *label
);
Retrieves the desired width of label
, in characters. See
gtk_label_set_width_chars()
.
|
a GtkLabel |
Returns : |
the width of the label in characters. |
Since 2.6
gint gtk_label_get_max_width_chars (GtkLabel *label
);
Retrieves the desired maximum width of label
, in characters. See
gtk_label_set_width_chars()
.
|
a GtkLabel |
Returns : |
the maximum width of the label in characters. |
Since 2.6
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_text()
).
|
a GtkLabel |
Returns : |
the text of the label widget. This string is owned by the widget and must not be modified or freed. |
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_layout_offsets()
.
The returned layout is owned by the label
so need not be
freed by the caller. The label
is free to recreate its layout at
any time, so it should be considered read-only.
|
a GtkLabel |
Returns : |
the PangoLayout for this label. [transfer none] |
gboolean gtk_label_get_line_wrap (GtkLabel *label
);
Returns whether lines in the label are automatically wrapped.
See gtk_label_set_line_wrap()
.
PangoWrapMode gtk_label_get_line_wrap_mode (GtkLabel *label
);
Returns line wrap mode used by the label. See gtk_label_set_line_wrap_mode()
.
Since 2.10
GtkWidget * gtk_label_get_mnemonic_widget (GtkLabel *label
);
Retrieves the target of the mnemonic (keyboard shortcut) of this
label. See gtk_label_set_mnemonic_widget()
.
gboolean gtk_label_get_selection_bounds (GtkLabel *label
,gint *start
,gint *end
);
Gets the selected range of characters in the label, returning TRUE
if there's a selection.
gboolean gtk_label_get_use_markup (GtkLabel *label
);
Returns whether the label's text is interpreted as marked up with
the gtk_label_set_use_markup()
.
gboolean gtk_label_get_use_underline (GtkLabel *label
);
Returns whether an embedded underline in the label indicates a
mnemonic. See gtk_label_set_use_underline()
.
gboolean gtk_label_get_single_line_mode (GtkLabel *label
);
Returns whether the label is in single line mode.
Since 2.6
gdouble gtk_label_get_angle (GtkLabel *label
);
Gets the angle of rotation for the label. See
gtk_label_set_angle()
.
|
a GtkLabel |
Returns : |
the angle of rotation for the label |
Since 2.6
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.
|
a GtkLabel |
|
the new text to set for the label |
void gtk_label_set_use_markup (GtkLabel *label
,gboolean setting
);
Sets whether the text of the label contains markup in gtk_label_set_markup()
.
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.
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
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.
|
a GtkLabel |
|
the angle that the baseline of the label makes with the horizontal, in degrees, measured counterclockwise |
Since 2.6
const gchar * gtk_label_get_current_uri (GtkLabel *label
);
Returns the URI for the currently active link in the label. The active link is the one under the mouse pointer or, in a selectable label, the link in which the text cursor is currently positioned.
This function is intended for use in a "activate-link" handler or for use in a "query-tooltip" handler.
|
a GtkLabel |
Returns : |
the currently active URI. The string is owned by GTK+ and must not be freed or modified. |
Since 2.18
void gtk_label_set_track_visited_links (GtkLabel *label
,gboolean track_links
);
Sets whether the label should keep track of clicked links (and use a different color for them).
Since 2.18