1QLabel(3qt)                                                        QLabel(3qt)
2
3
4

NAME

6       QLabel - Text or image display
7

SYNOPSIS

9       #include <qlabel.h>
10
11       Inherits QFrame.
12
13   Public Members
14       QLabel ( QWidget * parent, const char * name = 0, WFlags f = 0 )
15       QLabel ( const QString & text, QWidget * parent, const char * name = 0,
16           WFlags f = 0 )
17       QLabel ( QWidget * buddy, const QString & text, QWidget * parent, const
18           char * name = 0, WFlags f = 0 )
19       ~QLabel ()
20       QString text () const
21       QPixmap * pixmap () const
22       QPicture * picture () const
23       QMovie * movie () const
24       TextFormat textFormat () const
25       void setTextFormat ( TextFormat )
26       int alignment () const
27       virtual void setAlignment ( int )
28       int indent () const
29       void setIndent ( int )
30       bool autoResize () const  (obsolete)
31       virtual void setAutoResize ( bool enable )  (obsolete)
32       bool hasScaledContents () const
33       void setScaledContents ( bool )
34       virtual void setBuddy ( QWidget * buddy )
35       QWidget * buddy () const
36       virtual void setFont ( const QFont & f )
37
38   Public Slots
39       virtual void setText ( const QString & )
40       virtual void setPixmap ( const QPixmap & )
41       virtual void setPicture ( const QPicture & picture )
42       virtual void setMovie ( const QMovie & movie )
43       virtual void setNum ( int num )
44       virtual void setNum ( double num )
45       void clear ()
46
47   Properties
48       Alignment alignment - the alignment of the label's contents
49       BackgroundMode backgroundMode - the label's background mode  (read
50           only)
51       int indent - the label's text indent in pixels
52       QPixmap pixmap - the label's pixmap
53       bool scaledContents - whether the label will scale its contents to fill
54           all available space
55       QString text - the label's text
56       TextFormat textFormat - the label's text format
57
58   Protected Members
59       virtual void drawContents ( QPainter * p )
60

DESCRIPTION

62       The QLabel widget provides a text or image display.
63
64       QLabel is used for displaying text or an image. No user interaction
65       functionality is provided. The visual appearance of the label can be
66       configured in various ways, and it can be used for specifying a focus
67       accelerator key for another widget.
68
69       A QLabel can contain any of the following content types: <center>.nf
70
71       </center>
72
73       When the content is changed using any of these functions, any previous
74       content is cleared.
75
76       The look of a QLabel can be tuned in several ways. All the settings of
77       QFrame are available for specifying a widget frame. The positioning of
78       the content within the QLabel widget area can be tuned with
79       setAlignment() and setIndent(). For example, this code sets up a sunken
80       panel with a two-line text in the bottom right corner (both lines being
81       flush with the right side of the label):
82
83           QLabel *label = new QLabel( this );
84           label->setFrameStyle( QFrame::Panel | QFrame::Sunken );
85           label->setText( "first line\nsecond line" );
86           label->setAlignment( AlignBottom | AlignRight );
87
88       A QLabel is often used as a label for an interactive widget. For this
89       use QLabel provides a useful mechanism for adding an accelerator key
90       (see QAccel) that will set the keyboard focus to the other widget
91       (called the QLabel's "buddy"). For example:
92
93           QLineEdit* phoneEdit = new QLineEdit( this, "phoneEdit" );
94           QLabel* phoneLabel = new QLabel( phoneEdit, "&Phone:", this, "phoneLabel" );
95
96       In this example, keyboard focus is transferred to the label's buddy
97       (the QLineEdit) when the user presses Alt+P. You can also use the
98       setBuddy() function to accomplish the same thing.
99
100                                   [Image Omitted]
101
102                                   [Image Omitted]
103
104       See also QLineEdit, QTextEdit, QPixmap, QMovie, GUI Design Handbook:
105       Label, Basic Widgets, and Text Related Classes.
106

MEMBER FUNCTION DOCUMENTATION

QLabel::QLabel ( QWidget * parent, const char * name = 0, WFlags f = 0 )

109       Constructs an empty label.
110
111       The parent, name and widget flag f, arguments are passed to the QFrame
112       constructor.
113
114       See also alignment, setFrameStyle(), and indent.
115

QLabel::QLabel ( const QString & text, QWidget * parent, const char * name =

117       0, WFlags f = 0 )
118       Constructs a label that displays the text, text.
119
120       The parent, name and widget flag f, arguments are passed to the QFrame
121       constructor.
122
123       See also text, alignment, setFrameStyle(), and indent.
124

QLabel::QLabel ( QWidget * buddy, const QString & text, QWidget * parent,

126       const char * name = 0, WFlags f = 0 )
127       Constructs a label that displays the text text. The label has a buddy
128       widget, buddy.
129
130       If the text contains an underlined letter (a letter preceded by an
131       ampersand, &), and the text is in plain text format, when the user
132       presses Alt+ the underlined letter, focus is passed to the buddy
133       widget.
134
135       The parent, name and widget flag, f, arguments are passed to the QFrame
136       constructor.
137
138       See also text, setBuddy(), alignment, setFrameStyle(), and indent.
139

QLabel::~QLabel ()

141       Destroys the label.
142

int QLabel::alignment () const

144       Returns the alignment of the label's contents. See the "alignment"
145       property for details.
146

bool QLabel::autoResize () const

148       This function is obsolete. It is provided to keep old source working.
149       We strongly advise against using it in new code.
150
151       Returns TRUE if auto-resizing is enabled, or FALSE if auto-resizing is
152       disabled.
153
154       Auto-resizing is disabled by default.
155
156       See also setAutoResize().
157

QWidget * QLabel::buddy () const

159       Returns this label's buddy, or 0 if no buddy is currently set.
160
161       See also setBuddy().
162

void QLabel::clear () [slot]

164       Clears any label contents. Equivalent to setText( "" ).
165

void QLabel::drawContents ( QPainter * p ) [virtual protected]

167       Draws the label contents using the painter p.
168
169       Reimplemented from QFrame.
170

bool QLabel::hasScaledContents () const

172       Returns TRUE if the label will scale its contents to fill all available
173       space; otherwise returns FALSE. See the "scaledContents" property for
174       details.
175

int QLabel::indent () const

177       Returns the label's text indent in pixels. See the "indent" property
178       for details.
179

QMovie * QLabel::movie () const

181       Returns a pointer to the label's movie, or 0 if no movie has been set.
182
183       See also setMovie().
184

QPicture * QLabel::picture () const

186       Returns the label's picture or 0 if the label doesn't have a picture.
187

QPixmap * QLabel::pixmap () const

189       Returns the label's pixmap. See the "pixmap" property for details.
190

void QLabel::setAlignment ( int ) [virtual]

192       Sets the alignment of the label's contents. See the "alignment"
193       property for details.
194

void QLabel::setAutoResize ( bool enable ) [virtual]

196       This function is obsolete. It is provided to keep old source working.
197       We strongly advise against using it in new code.
198
199       Enables auto-resizing if enable is TRUE, or disables it if enable is
200       FALSE.
201
202       When auto-resizing is enabled the label will resize itself to fit the
203       contents whenever the contents change. The top-left corner is not
204       moved. This is useful for QLabel widgets that are not managed by a
205       QLayout (e.g., top-level widgets).
206
207       Auto-resizing is disabled by default.
208
209       See also autoResize(), adjustSize(), and sizeHint.
210

void QLabel::setBuddy ( QWidget * buddy ) [virtual]

212       Sets this label's buddy to buddy.
213
214       When the user presses the accelerator key indicated by this label, the
215       keyboard focus is transferred to the label's buddy widget.
216
217       The buddy mechanism is only available for QLabels that contain plain
218       text in which one letter is prefixed with an ampersand, &. This letter
219       is set as the accelerator key. The letter is displayed underlined, and
220       the '&' is not displayed (i.e. the ShowPrefix alignment flag is turned
221       on; see setAlignment()).
222
223       In a dialog, you might create two data entry widgets and a label for
224       each, and set up the geometry layout so each label is just to the left
225       of its data entry widget (its "buddy"), for example:
226
227           QLineEdit *nameEd  = new QLineEdit( this );
228           QLabel    *nameLb  = new QLabel( "&Name:", this );
229           nameLb->setBuddy( nameEd );
230           QLineEdit *phoneEd = new QLineEdit( this );
231           QLabel    *phoneLb = new QLabel( "&Phone:", this );
232           phoneLb->setBuddy( phoneEd );
233           // ( layout setup not shown )
234
235       With the code above, the focus jumps to the Name field when the user
236       presses Alt+N, and to the Phone field when the user presses Alt+P.
237
238       To unset a previously set buddy, call this function with buddy set to
239       0.
240
241       See also buddy(), text, QAccel, and alignment.
242
243       Examples:
244

void QLabel::setFont ( const QFont & f ) [virtual]

246       Sets the font used on the QLabel to font f.
247
248       Example: menu/menu.cpp.
249
250       Reimplemented from QWidget.
251

void QLabel::setIndent ( int )

253       Sets the label's text indent in pixels. See the "indent" property for
254       details.
255

void QLabel::setMovie ( const QMovie & movie ) [virtual slot]

257       Sets the label contents to movie. Any previous content is cleared.
258
259       The buddy accelerator, if any, is disabled.
260
261       The label resizes itself if auto-resizing is enabled.
262
263       See also movie() and setBuddy().
264

void QLabel::setNum ( int num ) [virtual slot]

266       Sets the label contents to plain text containing the textual
267       representation of integer num. Any previous content is cleared. Does
268       nothing if the integer's string representation is the same as the
269       current contents of the label.
270
271       The buddy accelerator, if any, is disabled.
272
273       The label resizes itself if auto-resizing is enabled.
274
275       See also text, QString::setNum(), and setBuddy().
276

void QLabel::setNum ( double num ) [virtual slot]

278       This is an overloaded member function, provided for convenience. It
279       behaves essentially like the above function.
280
281       Sets the label contents to plain text containing the textual
282       representation of double num. Any previous content is cleared. Does
283       nothing if the double's string representation is the same as the
284       current contents of the label.
285
286       The buddy accelerator, if any, is disabled.
287
288       The label resizes itself if auto-resizing is enabled.
289
290       See also text, QString::setNum(), and setBuddy().
291

void QLabel::setPicture ( const QPicture & picture ) [virtual slot]

293       Sets the label contents to picture. Any previous content is cleared.
294
295       The buddy accelerator, if any, is disabled.
296
297       See also picture() and setBuddy().
298

void QLabel::setPixmap ( const QPixmap & ) [virtual slot]

300       Sets the label's pixmap. See the "pixmap" property for details.
301

void QLabel::setScaledContents ( bool )

303       Sets whether the label will scale its contents to fill all available
304       space. See the "scaledContents" property for details.
305

void QLabel::setText ( const QString & ) [virtual slot]

307       Sets the label's text. See the "text" property for details.
308

void QLabel::setTextFormat ( TextFormat )

310       Sets the label's text format. See the "textFormat" property for
311       details.
312

QString QLabel::text () const

314       Returns the label's text. See the "text" property for details.
315

TextFormat QLabel::textFormat () const

317       Returns the label's text format. See the "textFormat" property for
318       details.
319
320   Property Documentation

Alignment alignment

322       This property holds the alignment of the label's contents.
323
324       The alignment is a bitwise OR of Qt::AlignmentFlags and Qt::TextFlags
325       values. The ExpandTabs, SingleLine and ShowPrefix flags apply only if
326       the label contains plain text; otherwise they are ignored. The DontClip
327       flag is always ignored. WordBreak applies to both rich text and plain
328       text labels. The BreakAnywhere flag is not supported in QLabel.
329
330       If the label has a buddy, the ShowPrefix flag is forced to TRUE.
331
332       The default alignment is AlignAuto | AlignVCenter | ExpandTabs if the
333       label doesn't have a buddy and AlignAuto | AlignVCenter | ExpandTabs |
334       ShowPrefix if the label has a buddy. If the label contains rich text,
335       additionally WordBreak is turned on.
336
337       See also Qt::AlignmentFlags, setBuddy(), and text.
338
339       Set this property's value with setAlignment() and get this property's
340       value with alignment().
341

BackgroundMode backgroundMode

343       This property holds the label's background mode.
344
345       Get this property with backgroundMode().
346
347       See also QWidget::backgroundMode.
348

int indent

350       This property holds the label's text indent in pixels.
351
352       If a label displays text, the indent applies to the left edge if
353       alignment() is AlignLeft, to the right edge if alignment() is
354       AlignRight, to the top edge if alignment() is AlignTop, and to to the
355       bottom edge if alignment() is AlignBottom.
356
357       If indent is negative, or if no indent has been set, the label computes
358       the effective indent as follows: If frameWidth() is 0, the effective
359       indent becomes 0. If frameWidth() is greater than 0, the effective
360       indent becomes half the width of the "x" character of the widget's
361       current font().
362
363       See also alignment, frameWidth, and font.
364
365       Set this property's value with setIndent() and get this property's
366       value with indent().
367

QPixmap pixmap

369       This property holds the label's pixmap.
370
371       If no pixmap has been set this will return an invalid pixmap.
372
373       Setting the pixmap clears any previous content, and resizes the label
374       if QLabel::autoResize() is TRUE. The buddy accelerator, if any, is
375       disabled.
376
377       Set this property's value with setPixmap() and get this property's
378       value with pixmap().
379

bool scaledContents

381       This property holds whether the label will scale its contents to fill
382       all available space.
383
384       When enabled and the label shows a pixmap, it will scale the pixmap to
385       fill the available space.
386
387       This property's default is FALSE.
388
389       See also scaledContents.
390
391       Set this property's value with setScaledContents() and get this
392       property's value with hasScaledContents().
393

QString text

395       This property holds the label's text.
396
397       If no text has been set this will return an empty string. Setting the
398       text clears any previous content, unless they are the same.
399
400       The text will be interpreted either as a plain text or as a rich text,
401       depending on the text format setting; see setTextFormat(). The default
402       setting is AutoText, i.e. QLabel will try to auto-detect the format of
403       the text set.
404
405       If the text is interpreted as a plain text and a buddy has been set,
406       the buddy accelerator key is updated from the new text.
407
408       The label resizes itself if auto-resizing is enabled.
409
410       Note that Qlabel is well-suited to display small rich text documents,
411       i.e. those small documents that get their document specific settings
412       (font, text color, link color) from the label's palette and font
413       properties. For large documents, use QTextEdit in read-only mode
414       instead. QTextEdit will flicker less on resize and can also provide a
415       scrollbar when necessary.
416
417       See also textFormat, setBuddy(), and alignment.
418
419       Set this property's value with setText() and get this property's value
420       with text().
421

TextFormat textFormat

423       This property holds the label's text format.
424
425       See the Qt::TextFormat enum for an explanation of the possible options.
426
427       The default format is AutoText.
428
429       See also text.
430
431       Set this property's value with setTextFormat() and get this property's
432       value with textFormat().
433
434

SEE ALSO

436       http://doc.trolltech.com/qlabel.html
437       http://www.trolltech.com/faq/tech.html
438
440       Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
441       license file included in the distribution for a complete license
442       statement.
443

AUTHOR

445       Generated automatically from the source code.
446

BUGS

448       If you find a bug in Qt, please report it as described in
449       http://doc.trolltech.com/bughowto.html.  Good bug reports help us to
450       help you. Thank you.
451
452       The definitive Qt documentation is provided in HTML format; it is
453       located at $QTDIR/doc/html and can be read using Qt Assistant or with a
454       web browser. This man page is provided as a convenience for those users
455       who prefer man pages, although this format is not officially supported
456       by Trolltech.
457
458       If you find errors in this manual page, please report them to qt-
459       bugs@trolltech.com.  Please include the name of the manual page
460       (qlabel.3qt) and the Qt version (3.3.8).
461
462
463
464Trolltech AS                    2 February 2007                    QLabel(3qt)
Impressum