|  | Home · Overviews · Examples |

# QLabel Class Reference
[com.trolltech.qt.gui module]

The `QLabel` widget provides a text or image display. More...

Inherits `QFrame`.

## Detailed Description

The `QLabel` widget provides a text or image display.

`QLabel` is used for displaying text or an image. 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 mnemonic key for another widget.

A `QLabel` can contain any of the following content types:

Content | Setting
--- | ---
Plain text | Pass a `QString` to `setText`.
Rich text | Pass a `QString` that contains rich text to `setText`.
A pixmap | Pass a `QPixmap` to `setPixmap`.
A movie | Pass a `QMovie` to `setMovie`.
A number | Pass an int or a double to `setNum`, which converts the number to plain text.
Nothing | The same as an empty plain text. This is the default. Set by `clear`.

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`. Text content can also wrap lines along word bounderies with `setWordWrap`. 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(this);
        label->setFrameStyle(QFrame::Panel | QFrame::Sunken);
        label->setText("first line\nsecond line");
        label->setAlignment(Qt::AlignBottom | Qt::AlignRight);

A `QLabel` is often used as a label for an interactive widget. For this use `QLabel` provides a useful mechanism for adding an mnemonic (see QKeysequence) that will set the keyboard focus to the other widget (called the `QLabel`'s "buddy"). For example:

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

In this example, keyboard focus is transferred to the label's buddy (the `QLineEdit`) when the user presses Alt+P. If the buddy was a button (inheriting from `QAbstractButton`), triggering the mnemonic would emulate a button click.

| A label shown in the Macintosh widget style.
| A label shown in the Plastique widget style.
| A label shown in the Windows XP widget style.

See also `QLineEdit`, `QTextEdit`, `QPixmap`, `QMovie`, and GUI Design Handbook: Label.