📄 gtklabel.html
字号:
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> setting);void <a class="link" href="GtkLabel.html#gtk-label-set-single-line-mode">gtk_label_set_single_line_mode</a> (<a class="link" href="GtkLabel.html" title="GtkLabel">GtkLabel</a> *label, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> single_line_mode);void <a class="link" href="GtkLabel.html#gtk-label-set-angle">gtk_label_set_angle</a> (<a class="link" href="GtkLabel.html" title="GtkLabel">GtkLabel</a> *label, <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gdouble">gdouble</a> angle);</pre></div><div class="refsect1" lang="en"><a name="id3453515"></a><h2>Object Hierarchy</h2><pre class="synopsis"> <ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a> +----<ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GInitiallyUnowned">GInitiallyUnowned</a> +----<a class="link" href="GtkObject.html" title="GtkObject">GtkObject</a> +----<a class="link" href="GtkWidget.html" title="GtkWidget">GtkWidget</a> +----<a class="link" href="GtkMisc.html" title="GtkMisc">GtkMisc</a> +----GtkLabel +----<a class="link" href="GtkAccelLabel.html" title="GtkAccelLabel">GtkAccelLabel</a> +----<a class="link" href="GtkTipsQuery.html" title="GtkTipsQuery">GtkTipsQuery</a></pre></div><div class="refsect1" lang="en"><a name="id3453584"></a><h2>Implemented Interfaces</h2><p>GtkLabel implements AtkImplementorIface and <a class="link" href="gtk-gtkbuildable.html#GtkBuildable">GtkBuildable</a>.</p></div><div class="refsect1" lang="en"><a name="id3453614"></a><h2>Properties</h2><pre class="synopsis"> "<a class="link" href="GtkLabel.html#GtkLabel--angle">angle</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gdouble">gdouble</a> : Read / Write "<a class="link" href="GtkLabel.html#GtkLabel--attributes">attributes</a>" <ahref="/usr/share/gtk-doc/html/pango/pango-Text-Attributes.html#PangoAttrList">PangoAttrList</a> : Read / Write "<a class="link" href="GtkLabel.html#GtkLabel--cursor-position">cursor-position</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> : Read "<a class="link" href="GtkLabel.html#GtkLabel--ellipsize">ellipsize</a>" <ahref="/usr/share/gtk-doc/html/pango/pango-Layout-Objects.html#PangoEllipsizeMode">PangoEllipsizeMode</a> : Read / Write "<a class="link" href="GtkLabel.html#GtkLabel--justify">justify</a>" <a class="link" href="gtk-Standard-Enumerations.html#GtkJustification">GtkJustification</a> : Read / Write "<a class="link" href="GtkLabel.html#GtkLabel--label">label</a>" <ahref="/usr/share/gtk-doc/html/gobject/gobject-Standard-Parameter-and-Value-Types.html#gchararray">gchararray</a> : Read / Write "<a class="link" href="GtkLabel.html#GtkLabel--max-width-chars">max-width-chars</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> : Read / Write "<a class="link" href="GtkLabel.html#GtkLabel--mnemonic-keyval">mnemonic-keyval</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#guint">guint</a> : Read "<a class="link" href="GtkLabel.html#GtkLabel--mnemonic-widget">mnemonic-widget</a>" <a class="link" href="GtkWidget.html" title="GtkWidget">GtkWidget</a> : Read / Write "<a class="link" href="GtkLabel.html#GtkLabel--pattern">pattern</a>" <ahref="/usr/share/gtk-doc/html/gobject/gobject-Standard-Parameter-and-Value-Types.html#gchararray">gchararray</a> : Write "<a class="link" href="GtkLabel.html#GtkLabel--selectable">selectable</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write "<a class="link" href="GtkLabel.html#GtkLabel--selection-bound">selection-bound</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> : Read "<a class="link" href="GtkLabel.html#GtkLabel--single-line-mode">single-line-mode</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write "<a class="link" href="GtkLabel.html#GtkLabel--use-markup">use-markup</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write "<a class="link" href="GtkLabel.html#GtkLabel--use-underline">use-underline</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write "<a class="link" href="GtkLabel.html#GtkLabel--width-chars">width-chars</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint">gint</a> : Read / Write "<a class="link" href="GtkLabel.html#GtkLabel--wrap">wrap</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write "<a class="link" href="GtkLabel.html#GtkLabel--wrap-mode">wrap-mode</a>" <ahref="/usr/share/gtk-doc/html/pango/pango-Layout-Objects.html#PangoWrapMode">PangoWrapMode</a> : Read / Write</pre></div><div class="refsect1" lang="en"><a name="id3453934"></a><h2>Signals</h2><pre class="synopsis"> "<a class="link" href="GtkLabel.html#GtkLabel-copy-clipboard">copy-clipboard</a>" : Run Last / Action "<a class="link" href="GtkLabel.html#GtkLabel-move-cursor">move-cursor</a>" : Run Last / Action "<a class="link" href="GtkLabel.html#GtkLabel-populate-popup">populate-popup</a>" : Run Last</pre></div><div class="refsect1" lang="en"><a name="id3453982"></a><h2>Description</h2><p>The <a class="link" href="GtkLabel.html" title="GtkLabel"><span class="type">GtkLabel</span></a> widget displays a small amount of text. As the nameimplies, most labels are used to label another widget such as a<a class="link" href="GtkButton.html" title="GtkButton"><span class="type">GtkButton</span></a>, a <a class="link" href="GtkMenuItem.html" title="GtkMenuItem"><span class="type">GtkMenuItem</span></a>, or a <a class="link" href="GtkOptionMenu.html" title="GtkOptionMenu"><span class="type">GtkOptionMenu</span></a>.</p><div class="refsect2" lang="en"><a name="id3454029"></a><h3>Mnemonics</h3><p>Labels may contain <em class="firstterm">mnemonics</em>. Mnemonics areunderlined characters in the label, used for keyboard navigation.Mnemonics are created by providing a string with an underscore beforethe mnemonic character, such as <code class="literal">"_File"</code>, to thefunctions <a class="link" href="GtkLabel.html#gtk-label-new-with-mnemonic"><code class="function">gtk_label_new_with_mnemonic()</code></a> or<a class="link" href="GtkLabel.html#gtk-label-set-text-with-mnemonic"><code class="function">gtk_label_set_text_with_mnemonic()</code></a>.</p><p>Mnemonics automatically activate any activatable widget the label isinside, such as a <a class="link" href="GtkButton.html" title="GtkButton"><span class="type">GtkButton</span></a>; if the label is not inside themnemonic's target widget, you have to tell the label about the targetusing <a class="link" href="GtkLabel.html#gtk-label-set-mnemonic-widget"><code class="function">gtk_label_set_mnemonic_widget()</code></a>. Here's a simple example wherethe label is inside a button:</p><div class="informalexample"><pre class="programlisting"> /* 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);</pre></div><p>There's a convenience function to create buttons with a mnemonic label already inside:</p><div class="informalexample"><pre class="programlisting"> /* Pressing Alt+H will activate this button */ button = gtk_button_new_with_mnemonic ("_Hello");</pre></div><p>To create a mnemonic for a widget alongside the label, such as a <a class="link" href="GtkEntry.html" title="GtkEntry"><span class="type">GtkEntry</span></a>, you have to point the label at the entry with <a class="link" href="GtkLabel.html#gtk-label-set-mnemonic-widget"><code class="function">gtk_label_set_mnemonic_widget()</code></a>:</p><div class="informalexample"><pre class="programlisting"> /* 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);</pre></div><p></p></div><hr><div class="refsect2" lang="en"><a name="id3454165"></a><h3>Markup (styled text)</h3><p>To make it easy to format text in a label (changing colors, fonts,etc.), label text can be provided in a simple <ahref="/usr/share/gtk-doc/html/pango/PangoMarkupFormat.html">markup format</a>.Here's how to create a label with a small font:</p><div class="informalexample"><pre class="programlisting"> label = gtk_label_new (NULL); gtk_label_set_markup (GTK_LABEL (label), "<small>Small text</small>");</pre></div><p>(See <ahref="/usr/share/gtk-doc/html/pango/PangoMarkupFormat.html">complete documentation</a> of availabletags in the Pango manual.)</p><p>The markup passed to <a class="link" href="GtkLabel.html#gtk-label-set-markup"><code class="function">gtk_label_set_markup()</code></a> must be valid; for example,literal </>/& characters must be escaped as &lt;,&gt;, and &amp;. If you pass text obtained from the user, file,or a network to <a class="link" href="GtkLabel.html#gtk-label-set-markup"><code class="function">gtk_label_set_markup()</code></a>, you'll want to escape it with<ahref="/usr/share/gtk-doc/html/glib/glib-Simple-XML-Subset-Parser.html#g-markup-escape-text"><code class="function">g_markup_escape_text()</code></a> or <ahref="/usr/share/gtk-doc/html/glib/glib-Simple-XML-Subset-Parser.html#g-markup-printf-escaped"><code class="function">g_markup_printf_escaped()</code></a>.</p><p>Markup strings are just a convenient way to set the <ahref="/usr/share/gtk-doc/html/pango/pango-Text-Attributes.html#PangoAttrList"><span class="type">PangoAttrList</span></a> ona label; <a class="link" href="GtkLabel.html#gtk-label-set-attributes"><code class="function">gtk_label_set_attributes()</code></a> may be a simpler way to setattributes in some cases. Be careful though; <ahref="/usr/share/gtk-doc/html/pango/pango-Text-Attributes.html#PangoAttrList"><span class="type">PangoAttrList</span></a> tends tocause internationalization problems, unless you're applying attributesto the entire string (i.e. unless you set the range of each attributeto [0, G_MAXINT)). The reason is that specifying the start_index andend_index for a <ahref="/usr/share/gtk-doc/html/pango/pango-Text-Attributes.html#PangoAttribute"><span class="type">PangoAttribute</span></a> requires knowledge of the exact stringbeing displayed, so translations will cause problems.</p></div><hr><div class="refsect2" lang="en"><a name="id3454303"></a><h3>Selectable labels</h3><p>Labels can be made selectable with <a class="link" href="GtkLabel.html#gtk-label-set-selectable"><code class="function">gtk_label_set_selectable()</code></a>. Selectable labels allow the user to copy the label contents to the clipboard. Only labels that contain useful-to-copy information— such as error messages — should be made selectable.</p></div><hr><div class="refsect2" lang="en"><a name="id3454324"></a><h3>Text layout</h3><p>A label can contain any number of paragraphs, but will haveperformance problems if it contains more than a small number.Paragraphs are separated by newlines or other paragraph separatorsunderstood by Pango.</p><p>Labels can automatically wrap text if you call<a class="link" href="GtkLabel.html#gtk-label-set-line-wrap"><code class="function">gtk_label_set_line_wrap()</code></a>.</p><p><a class="link" href="GtkLabel.html#gtk-label-set-justify"><code class="function">gtk_label_set_justify()</code></a> sets how the lines in a label align with one another. If you want to set how the label as a whole aligns in its available space, see <a class="link" href="GtkMisc.html#gtk-misc-set-alignment"><code class="function">gtk_misc_set_alignment()</code></a>.</p></div></div><div class="refsect1" lang="en"><a name="id3454386"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3454396"></a><h3><a name="GtkLabel-struct"></a>GtkLabel</h3><a class="indexterm" name="id3454409"></a><pre class="programlisting">typedef struct _GtkLabel GtkLabel;</pre><p>This should not be accessed directly. Use the accessor functions asdescribed below.</p></div><hr><div class="refsect2" lang="en">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -