QLabel Class Reference


The QLabel widget displays a static text. (details) (complete member list)

#include <qlabel.h>

Inherits QFrame.

Public Members

Public Slots

Protected Members


Detailed Description

The QLabel widget displays a static text.

A label is a text field that can have an optional frame (since QLabel inherits QFrame).

The contents of a label can be specified as a normal text or as a numeric value (which is internally converted to a text).

A label can be aligned in many different ways. The alignment setting specifies where to position the contents relative to the frame rectangle. See setAlignment() for a description of the alignment flags.

Enabling auto-resizing will make a label resize itself whenever the contents change.

Example of use:

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

Member Function Documentation

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

Constructs an empty label which is left-aligned, vertically centered and without automatic resizing.

The parent and name arguments are passed to the QWidget constructor.

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

Constructs a label with a text. The label is left-aligned, vertically centered and without automatic resizing.

The parent and name arguments are passed to the QWidget constructor.

void QLabel::adjustSize ()

Adjusts the size of the label to fit the contents.

This function is called automatically whenever the contents change and auto-resizing is enabled.

See also: setAutoResizing().

int QLabel::alignment () const

Returns the alignment setting.

The default alignment is AlignLeft | AlignVCenter | ExpandTabs.

See also: setAlignment().

bool QLabel::autoResizing () const

Returns TRUE if auto-resizing is enabled, or FALSE if auto-resizing is disabled.

Auto-resizing is disabled by default.

See also: setAutoResizing().

void QLabel::drawContents (QPainter *p)

Draws the label contents using the painter p.

void QLabel::setAlignment (int alignment)

Sets the alignment of the label contents and redraws itself.

The alignment is the bitwise OR of the following flags:

See also: alignment().

void QLabel::setAutoResizing (bool enable)

Enables auto-resizing if enable is TRUE, or disables it if enable is FALSE.

When auto-resizing is enabled, the label will resize itself whenever the contents change.

See also: autoResizing() and adjustSize().

void QLabel::setNum (long num)

Sets the label contents to num (converts it to text) and redraws the contents.

The label resizes itself if auto-resizing is enabled.

See also: setAutoResize().

void QLabel::setNum (double num)

Sets the label contents to num (converts it to text) and redraws the contents.

The label resizes itself if auto-resizing is enabled.

See also: setAutoResize().

void QLabel::setNum (int num)

Sets the label contents to num (converts it to text) and redraws the contents.

The label resizes itself if auto-resizing is enabled.

See also: setAutoResize().

void QLabel::setNum (float num)

Sets the label contents to num (converts it to text) and redraws the contents.

The label resizes itself if auto-resizing is enabled.

See also: setAutoResize().

void QLabel::setText (const char *text)

Sets the label contents to text and redraws the contents.

The label resizes itself if auto-resizing is enabled.

See also: setAutoResize().

const char * QLabel::text () const

Returns the label text.

void QLabel::updateLabel ()

Updates the label, not the frame.


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

It was generated from the following files:


Generated at 16:17, 1995/06/30 by the webmaster at Troll Tech