File: chapter-misc-widgets.html

package info (click to toggle)
gtkmm-documentation 4.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,772 kB
  • sloc: cpp: 15,541; javascript: 1,208; makefile: 1,080; python: 401; xml: 106; perl: 67; sh: 8
file content (264 lines) | stat: -rw-r--r-- 9,694 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="highlight.min.css">
<script src="highlight.min.js"></script><script>
      hljs.configure({languages: ['cpp']});
      hljs.highlightAll();
    </script><title>Chapter 8. Miscellaneous Widgets</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="Programming with gtkmm 4">
<link rel="up" href="index.html" title="Programming with gtkmm 4">
<link rel="prev" href="sec-range-example.html" title="Example">
<link rel="next" href="sec-text-entry.html" title="Entry">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Chapter 8. Miscellaneous Widgets</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-range-example.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center"> </th>
<td width="20%" align="right"> <a accesskey="n" href="sec-text-entry.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="chapter-misc-widgets"></a>Chapter 8. Miscellaneous Widgets</h1></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<ul class="toc">
<li><span class="section"><a href="chapter-misc-widgets.html#sec-labels">Label</a></span></li>
<li><span class="section"><a href="sec-text-entry.html">Entry</a></span></li>
<li><span class="section"><a href="sec-spinbutton.html">SpinButton</a></span></li>
<li><span class="section"><a href="sec-progressbar.html">ProgressBar</a></span></li>
<li><span class="section"><a href="sec-infobar.html">InfoBar</a></span></li>
<li><span class="section"><a href="sec-tooltips.html">Tooltips</a></span></li>
</ul>
</div>


<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-labels"></a>Label</h2></div></div></div>


<p>
Labels are the  main method of placing non-editable text in windows, for
instance to place a title next to an <code class="classname">Entry</code> widget. You
can specify the text in the constructor, or later with the
<code class="methodname">set_text()</code> or <code class="methodname">set_markup()</code> methods.
</p>

<p>
The width of the label will be adjusted automatically. You can produce multi-line labels by putting line breaks ("\n") in the label string.
</p>

<p>
The label text can be justified using the <code class="methodname">set_justify()</code>
method. The widget is also capable of word-wrapping, which can be activated
with <code class="methodname">set_wrap()</code>.
</p>

<p>
Gtk::Label supports some simple formatting, for instance allowing you to make some
text bold, colored, or larger. You can do this by providing a string to
<code class="methodname">set_markup()</code>, using the <a class="ulink" href="https://docs.gtk.org/Pango/pango_markup.html" target="_top">Pango Markup syntax</a>. For instance,
<code class="code">
&lt;b&gt;bold text&lt;/b&gt; and &lt;s&gt;strikethrough text&lt;/s&gt;
</code>
.</p>

<p><a class="ulink" href="https://gnome.pages.gitlab.gnome.org/gtkmm/classGtk_1_1Label.html" target="_top">Reference</a></p>

<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="label-example"></a>Example</h3></div></div></div>

<p>
Below is a short example to illustrate these functions. This example
makes use of the Frame widget to better demonstrate the label styles.
 (The Frame widget is explained in the <a class="link" href="chapter-container-widgets.html#sec-frame" title="Frame">Frame</a> section.)
It is possible that the first character in <code class="literal">m_Label_Normal</code> is shown
underlined only when you press the <span class="keycap"><strong>Alt</strong></span> key.
</p>

<div class="figure">
<a name="figure-label"></a><p class="title"><b>Figure 8.1. Label</b></p>
<div class="figure-contents">
  
  <div class="screenshot">
    <div class="mediaobject"><img src="figures/label.png" alt="Label"></div>
  </div>
</div>
</div>
<br class="figure-break">

<p><a class="ulink" href="https://gitlab.gnome.org/GNOME/gtkmm-documentation/tree/master/examples/book/label" target="_top">Source Code</a></p>

<p>File: <code class="filename">examplewindow.h</code> (For use with gtkmm 4)</p>
<pre class="programlisting"><code class="code">#ifndef GTKMM_EXAMPLEWINDOW_H
#define GTKMM_EXAMPLEWINDOW_H

#include &lt;gtkmm.h&gt;

class ExampleWindow : public Gtk::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

protected:

  //Child widgets:
  Gtk::Box m_HBox;
  Gtk::Box m_VBox, m_VBox2;
  Gtk::Frame m_Frame_Normal, m_Frame_Multi, m_Frame_Left, m_Frame_Right,
    m_Frame_LineWrapped, m_Frame_FilledWrapped, m_Frame_Underlined;
  Gtk::Label m_Label_Normal, m_Label_Multi, m_Label_Left, m_Label_Right,
    m_Label_LineWrapped, m_Label_FilledWrapped, m_Label_Underlined;
};

#endif //GTKMM_EXAMPLEWINDOW_H
</code></pre>
<p>File: <code class="filename">examplewindow.cc</code> (For use with gtkmm 4)</p>
<pre class="programlisting"><code class="code">#include "examplewindow.h"
#include &lt;iostream&gt;

ExampleWindow::ExampleWindow()
:
  m_HBox(Gtk::Orientation::HORIZONTAL, 5),
  m_VBox(Gtk::Orientation::VERTICAL, 5),
  m_VBox2(Gtk::Orientation::VERTICAL, 5),
  m_Frame_Normal("Normal Label"),
  m_Frame_Multi("Multi-line Label"),
  m_Frame_Left("Left Justified Label"),
  m_Frame_Right("Right Justified Label"),
  m_Frame_LineWrapped("Line wrapped label"),
  m_Frame_FilledWrapped("Filled, wrapped label"),
  m_Frame_Underlined("Underlined label"),
  m_Label_Normal("_This is a Normal label", true),
  m_Label_Multi("This is a Multi-line label.\nSecond line\nThird line"),
  m_Label_Left("This is a Left-Justified\nMulti-line label.\nThird line"),
  m_Label_Right("This is a Right-Justified\nMulti-line label.\nThird line"),
  m_Label_Underlined("&lt;u&gt;This label is underlined!&lt;/u&gt;\n"
          "&lt;u&gt;T&lt;/u&gt;h&lt;u&gt;is one is&lt;/u&gt; &lt;u&gt;u&lt;/u&gt;n&lt;u&gt;derlin&lt;/u&gt;ed "
          "in&lt;u&gt; q&lt;/u&gt;u&lt;u&gt;ite a f&lt;/u&gt;u&lt;u&gt;nky&lt;/u&gt; fashion")
{
  set_title("Label");

  m_HBox.set_margin(5);
  set_child(m_HBox);

  m_HBox.append(m_VBox);

  m_Frame_Normal.set_child(m_Label_Normal);
  m_VBox.append(m_Frame_Normal);

  m_Frame_Multi.set_child(m_Label_Multi);
  m_VBox.append(m_Frame_Multi);

  m_Label_Left.set_justify(Gtk::Justification::LEFT);
  m_Frame_Left.set_child(m_Label_Left);
  m_VBox.append(m_Frame_Left);

  m_Label_Right.set_justify(Gtk::Justification::RIGHT);
  m_Frame_Right.set_child(m_Label_Right);
  m_VBox.append(m_Frame_Right);

  m_HBox.append(m_VBox2);

  m_Label_LineWrapped.set_text(
          "This is an example of a line-wrapped label.  It "
          /* add a big space to the next line to test spacing */
          "should not be taking up the entire             "
          "width allocated to it, but automatically "
          "wraps the words to fit.  "
          "The time has come, for all good men, to come to "
          "the aid of their party.  "
          "The sixth sheik's six sheep's sick.\n"
          "     It supports multiple paragraphs correctly, "
          "and  correctly   adds "
          "many          extra  spaces. ");
  m_Label_LineWrapped.set_wrap();
  m_Frame_LineWrapped.set_child(m_Label_LineWrapped);
  m_VBox2.append(m_Frame_LineWrapped);

  m_Label_FilledWrapped.set_text(
          "This is an example of a line-wrapped, filled label.  "
          "It should be taking "
          "up the entire              width allocated to it.  "
          "Here is a sentence to prove "
          "my point.  Here is another sentence. "
          "Here comes the sun, do de do de do.\n"
          "    This is a new paragraph.\n"
          "    This is another newer, longer, better "
          "paragraph.  It is coming to an end, "
          "unfortunately.");
  m_Label_FilledWrapped.set_justify(Gtk::Justification::FILL);
  m_Label_FilledWrapped.set_wrap();
  m_Frame_FilledWrapped.set_child(m_Label_FilledWrapped);
  m_VBox2.append(m_Frame_FilledWrapped);

  m_Label_Underlined.set_justify(Gtk::Justification::LEFT);
  m_Label_Underlined.set_use_markup(true);
  m_Frame_Underlined.set_child(m_Label_Underlined);
  m_VBox2.append(m_Frame_Underlined);
}

ExampleWindow::~ExampleWindow()
{
}
</code></pre>
<p>File: <code class="filename">main.cc</code> (For use with gtkmm 4)</p>
<pre class="programlisting"><code class="code">#include "examplewindow.h"
#include &lt;gtkmm/application.h&gt;

int main(int argc, char *argv[])
{
  auto app = Gtk::Application::create("org.gtkmm.example");

  //Shows the window and returns when it is closed.
  return app-&gt;make_window_and_run&lt;ExampleWindow&gt;(argc, argv);
}
</code></pre>


</div>

</div>










</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-range-example.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"> </td>
<td width="40%" align="right"> <a accesskey="n" href="sec-text-entry.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Example </td>
<td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> Entry</td>
</tr>
</table>
</div>
</body>
</html>