Qt logo

QLabel Class Reference


The QLabel widget provides a static information display More...

#include <qlabel.h>

Inherits QFrame.

List of all member functions.

Public Slots

Protected Members


Detailed Description

The QLabel widget provides a static information display

QLabel is used for displaying information in the form of text or image to the user. No user interaction functionality is provided. The visual appearance of the label can be configured in various ways, and it can be used for specifying a focus accellerator key for another widget.

A QLabel can contain any of the following content types:

When the content is changed using any of these functions, any previous content is cleared.

The look of a QLabel can be tuned in several ways. All the settings of QFrame are available for specifying a widget frame. The positioning of the content within the QLabel widget area can be tuned with setAlignment() and setIndent(). For example, this code sets up a sunken panel with a two-line text in the bottom right corner (both lines being flush with the right side of the label):

    QLabel *label = new QLabel;
    label->setFrameStyle( QFrame::Panel | QFrame::Sunken );
    label->setText( "first line\nsecond line" );
    label->setAlignment( AlignBottom | AlignRight );

A QLabel is often used as a label for another, interactive widget. For this use, QLabel provides a handy mechanism for adding an accellerator key (see QAccel) that will set the keyboard focus to the other widget (called the QLabel's "buddy"). Example:

     QLineEdit* phoneEdit = new QLineEdit( this, "phoneEdit" );
     QLabel* phoneLabel = new QLabel( phoneEdit, "&Phone:", this, "phoneLabel" );

In this example, keyboard focus is transferred to the label's buddy (the QLineEdit) when the user presses Alt-P. You can also use the setBuddy() function to accomplish the same.

See also: QLineEdit, QTextView, QPixmap, QMovie and GUI Design Handbook: Label

Examples: qdir/qdir.cpp tabdialog/tabdialog.cpp cursor/cursor.cpp layout/layout.cpp popup/popup.cpp menu/menu.cpp progress/progress.cpp qmag/qmag.cpp movies/main.cpp customlayout/main.cpp


Member Function Documentation

void QLabel::clear () [slot]

Clears any label contents. Equivalent with setText( "" ).

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

Draws the label contents using the painter p.

Reimplemented from QFrame.

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

Draws the label contents mask using the painter p. Used only in transparent mode.

See also: QWidget::setAutoMask();.

Reimplemented from QFrame.

void QLabel::fontChange ( const QFont & ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

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

Sets the label contents to movie. Any previous content is cleared.

The buddy accelerator, if any, is disabled.

The label resizes itself if auto-resizing is enabled.

See also: movie() and setBuddy().

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

Sets the label contents to a plain text containing the printed value of num. Does nothing if this is equal to the current contents of the label. Any previous content is cleared.

The buddy accelerator, if any, is disabled.

The label resizes itself if auto-resizing is enabled.

See also: setText(), QString::setNum() and setBuddy().

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

Sets the label contents to a plain text containing the printed value of num. Does nothing if this is equal to the current contents of the label. Any previous content is cleared.

The buddy accelerator, if any, is disabled.

The label resizes itself if auto-resizing is enabled.

See also: setText(), QString::setNum() and setBuddy().

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

Sets the label contents to pixmap. Any previous content is cleared.

The buddy accelerator, if any, is disabled.

The label resizes itself if auto-resizing is enabled.

See also: pixmap() and setBuddy().

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

Sets the label contents to text, or does nothing if text is equal to the current contents of the label. Any previous content is cleared.

text will be interpreted either as a plain text or as a rich text, depending on the text format setting; see setTextFormat(). The default setting is AutoText, i.e. QLabel will try to auto-detect the format of text.

If text is interpreted as a plain text, and a buddy has been set, the buddy accelerator key is updated from the new text.

The label resizes itself if auto-resizing is enabled.

Note that Qlabel is well suited to display small rich text documents only. For large documents, use QTextView instead. It will flicker less on resize and can also provide a scrollbar if necessary.

See also: text(), setTextFormat(), setBuddy() and setAlignment().

Examples: cursor/cursor.cpp layout/layout.cpp popup/popup.cpp qmag/qmag.cpp customlayout/main.cpp


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-2000 Troll Tech, all rights reserved.


Copyright İ 2000 Troll TechTrademarks
Qt version 2.1.0 (pre-release)