QLabel Class Reference

#include <qlabel.h>

Inheritance diagram for QLabel:

Inheritance graph
[legend]
Collaboration diagram for QLabel:

Collaboration graph
[legend]
List of all members.

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.

100% macintosh-label.png Screenshot of a Macintosh style label A label shown in the {Macintosh Style Widget Gallery}{Macintosh widget style}. plastique-label.png Screenshot of a Plastique style label A label shown in the {Plastique Style Widget Gallery}{Plastique widget style}. windowsxp-label.png Screenshot of a Windows XP style label A label shown in the {Windows XP Style Widget Gallery}{Windows XP widget style}.

See also:
QLineEdit, QTextEdit, QPixmap, QMovie, {fowler}{GUI Design Handbook: Label}

Definition at line 35 of file qlabel.h.

Public Slots

void setText (const QString &)
void setPixmap (const QPixmap &)
void setPicture (const QPicture &)
void setMovie (QMovie *movie)
void setNum (int)
void setNum (double)
void clear ()

Signals

void linkActivated (const QString &link)
void linkHovered (const QString &link)

Public Member Functions

 QLabel (QWidget *parent=0, Qt::WindowFlags f=0)
 QLabel (const QString &text, QWidget *parent=0, Qt::WindowFlags f=0)
 ~QLabel ()
QString text () const
const QPixmappixmap () const
const QPicturepicture () const
QMoviemovie () const
Qt::TextFormat textFormat () const
void setTextFormat (Qt::TextFormat)
Qt::Alignment alignment () const
void setAlignment (Qt::Alignment)
void setWordWrap (bool on)
bool wordWrap () const
int indent () const
void setIndent (int)
int margin () const
void setMargin (int)
bool hasScaledContents () const
void setScaledContents (bool)
QSize sizeHint () const
QSize minimumSizeHint () const
void setBuddy (QWidget *)
QWidgetbuddy () const
int heightForWidth (int) const
bool openExternalLinks () const
void setOpenExternalLinks (bool open)
void setTextInteractionFlags (Qt::TextInteractionFlags flags)
Qt::TextInteractionFlags textInteractionFlags () const

Protected Member Functions

bool event (QEvent *e)
void keyPressEvent (QKeyEvent *ev)
void paintEvent (QPaintEvent *)
void changeEvent (QEvent *)
void mousePressEvent (QMouseEvent *ev)
void mouseMoveEvent (QMouseEvent *ev)
void mouseReleaseEvent (QMouseEvent *ev)
void contextMenuEvent (QContextMenuEvent *ev)
void focusInEvent (QFocusEvent *ev)
void focusOutEvent (QFocusEvent *ev)
bool focusNextPrevChild (bool next)

Private Member Functions

 Q_PRIVATE_SLOT (d_func(), void _q_movieUpdated(const QRect &)) Q_PRIVATE_SLOT(d_func()
void _q_movieResized (const QSize &)) Q_PRIVATE_SLOT(d_func()
void void _q_linkHovered (const QString &)) friend class QTipLabel

Friends

class QMessageBoxPrivate


Constructor & Destructor Documentation

QLabel::QLabel ( QWidget parent = 0,
Qt::WindowFlags  f = 0 
) [explicit]

Constructs an empty label.

The parent and widget flag f, arguments are passed to the QFrame constructor.

See also:
setAlignment(), setFrameStyle(), setIndent()

Definition at line 143 of file qlabel.cpp.

References d.

00144     : QFrame(*new QLabelPrivate(), parent, f)
00145 {
00146     Q_D(QLabel);
00147     d->init();
00148 }

QLabel::QLabel ( const QString text,
QWidget parent = 0,
Qt::WindowFlags  f = 0 
) [explicit]

Constructs a label that displays the text, text.

The parent and widget flag f, arguments are passed to the QFrame constructor.

See also:
setText(), setAlignment(), setFrameStyle(), setIndent()

Definition at line 158 of file qlabel.cpp.

References d, setText(), and text().

00159         : QFrame(*new QLabelPrivate(), parent, f)
00160 {
00161     Q_D(QLabel);
00162     d->init();
00163     setText(text);
00164 }

Here is the call graph for this function:

QLabel::~QLabel (  ) 

Destroys the label.

Definition at line 242 of file qlabel.cpp.

References d.

00243 {
00244     Q_D(QLabel);
00245     d->clearContents();
00246 }


Member Function Documentation

QString QLabel::text (  )  const

Definition at line 338 of file qlabel.cpp.

References d.

Referenced by qdesigner_internal::LabelTaskMenu::editText(), EditorPage::fontChange(), Q3ProgressDialog::labelText(), EditorPage::layoutWidgets(), DragLabel::mousePressEvent(), QLabel(), QTipLabel::QTipLabel(), Dialog::setExistingDirectory(), Dialog::setFont(), Dialog::setOpenFileName(), Dialog::setSaveFileName(), setText(), and LCDRange::text().

00339 {
00340     Q_D(const QLabel);
00341     return d->text;
00342 }

const QPixmap * QLabel::pixmap (  )  const

Definition at line 378 of file qlabel.cpp.

References d.

Referenced by DropArea::extractPixmap(), DragWidget::mousePressEvent(), ImageViewer::print(), Screenshot::resizeEvent(), ImageViewer::scaleImage(), and setPixmap().

00379 {
00380     Q_D(const QLabel);
00381     return d->pixmap;
00382 }

const QPicture * QLabel::picture (  )  const

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

Definition at line 127 of file qlabel.cpp.

References d.

Referenced by setPicture().

00128 {
00129     Q_D(const QLabel);
00130     return d->picture;
00131 }

QMovie * QLabel::movie (  )  const

Returns a pointer to the label's movie, or 0 if no movie has been set.

See also:
setMovie()

Definition at line 1206 of file qlabel.cpp.

References d.

Referenced by setMovie().

01207 {
01208     Q_D(const QLabel);
01209     return d->movie;
01210 }

Qt::TextFormat QLabel::textFormat (  )  const

Definition at line 1226 of file qlabel.cpp.

References d.

Referenced by qdesigner_internal::LabelTaskMenu::editText().

01227 {
01228     Q_D(const QLabel);
01229     return d->textformat;
01230 }

void QLabel::setTextFormat ( Qt::TextFormat   ) 

Definition at line 1232 of file qlabel.cpp.

References d, setText(), and t.

Referenced by DropArea::dropEvent(), and QBalloonTip::QBalloonTip().

01233 {
01234     Q_D(QLabel);
01235     if (format != d->textformat) {
01236         d->textformat = format;
01237         QString t = d->text;
01238         if (!t.isNull()) {
01239             d->text.clear();
01240             setText(t);
01241         }
01242     }
01243 }

Qt::Alignment QLabel::alignment (  )  const

Definition at line 479 of file qlabel.cpp.

References Qt::AlignHorizontal_Mask, Qt::AlignVertical_Mask, and d.

00480 {
00481     Q_D(const QLabel);
00482     return QFlag(d->align & (Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask));
00483 }

void QLabel::setAlignment ( Qt::Alignment   ) 

Definition at line 453 of file qlabel.cpp.

References Qt::AlignHorizontal_Mask, Qt::AlignVertical_Mask, and d.

Referenced by qdesigner_internal::ActionFilterWidget::ActionFilterWidget(), IconPreviewArea::createHeaderLabel(), TetrixWindow::createLabel(), IconPreviewArea::createPixmapLabel(), DetailsDialog::DetailsDialog(), DropArea::DropArea(), QMessageBoxPrivate::init(), QProgressDialogPrivate::init(), LCDRange::init(), MoviePlayer::MoviePlayer(), Q3ProgressDialogData::Q3ProgressDialogData(), QBalloonTip::QBalloonTip(), QColorShower::QColorShower(), QTipLabel::QTipLabel(), SpreadSheet::runInputDialog(), Screenshot::Screenshot(), QMessageBox::setInformativeText(), Oubliette::showInventory(), and TetrixWindow::TetrixWindow().

00454 {
00455     Q_D(QLabel);
00456     if (alignment == (d->align & (Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask)))
00457         return;
00458     d->align = (d->align & ~(Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask))
00459                | (alignment & (Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask));
00460 
00461     d->updateLabel();
00462 }

void QLabel::setWordWrap ( bool  on  ) 

Definition at line 493 of file qlabel.cpp.

References d, and Qt::TextWordWrap.

Referenced by DropSiteWindow::DropSiteWindow(), QTipLabel::QTipLabel(), QMessageBox::setInformativeText(), QMessageBoxPrivate::updateSize(), and VersionDialog::VersionDialog().

00494 {
00495     Q_D(QLabel);
00496     if (on)
00497         d->align |= Qt::TextWordWrap;
00498     else
00499         d->align &= ~Qt::TextWordWrap;
00500 
00501     d->updateLabel();
00502 }

bool QLabel::wordWrap (  )  const

Definition at line 504 of file qlabel.cpp.

References d, and Qt::TextWordWrap.

Referenced by QMessageBoxPrivate::updateSize().

00505 {
00506     Q_D(const QLabel);
00507     return d->align & Qt::TextWordWrap;
00508 }

int QLabel::indent (  )  const

Definition at line 535 of file qlabel.cpp.

References d.

00536 {
00537     Q_D(const QLabel);
00538     return d->indent;
00539 }

void QLabel::setIndent ( int   ) 

Definition at line 528 of file qlabel.cpp.

References d.

Referenced by qdesigner_internal::AbstractPropertyGroup::createEditor(), Window::createMessageGroupBox(), QMessageBoxPrivate::init(), QTipLabel::QTipLabel(), qdesigner_internal::RoleEditor::RoleEditor(), and QMessageBox::setInformativeText().

00529 {
00530     Q_D(QLabel);
00531     d->indent = indent;
00532     d->updateLabel();
00533 }

int QLabel::margin (  )  const

Definition at line 553 of file qlabel.cpp.

References d.

00554 {
00555     Q_D(const QLabel);
00556     return d->margin;
00557 }

void QLabel::setMargin ( int   ) 

Definition at line 559 of file qlabel.cpp.

References d.

Referenced by AnimationSaveWidget::AnimationSaveWidget(), and QTipLabel::QTipLabel().

00560 {
00561     Q_D(QLabel);
00562     if (d->margin == margin)
00563         return;
00564     d->margin = margin;
00565     d->updateLabel();
00566 }

bool QLabel::hasScaledContents (  )  const

Definition at line 1272 of file qlabel.cpp.

References d.

01273 {
01274     Q_D(const QLabel);
01275     return d->scaledcontents;
01276 }

void QLabel::setScaledContents ( bool   ) 

Definition at line 1278 of file qlabel.cpp.

References QWidget::contentsRect(), d, and QWidget::update().

Referenced by MoviePlayer::fitToWindow(), and ImageViewer::ImageViewer().

01279 {
01280     Q_D(QLabel);
01281     if ((bool)d->scaledcontents == enable)
01282         return;
01283     d->scaledcontents = enable;
01284     if (!enable) {
01285         delete d->scaledpixmap;
01286         d->scaledpixmap = 0;
01287         delete d->cachedimage;
01288         d->cachedimage = 0;
01289     }
01290     update(contentsRect());
01291 }

Here is the call graph for this function:

QSize QLabel::sizeHint (  )  const [virtual]

Reimplemented from QFrame.

Definition at line 709 of file qlabel.cpp.

References d, and minimumSizeHint().

Referenced by KAstTopLevel::KAstTopLevel(), QTipLabel::QTipLabel(), Q3ProgressDialog::sizeHint(), Q3FileDialog::updateGeometries(), and Window::Window().

00710 {
00711     Q_D(const QLabel);
00712     if (!d->valid_hints)
00713         (void) QLabel::minimumSizeHint();
00714     return d->sh;
00715 }

Here is the call graph for this function:

QSize QLabel::minimumSizeHint (  )  const [virtual]

Reimplemented from QWidget.

Definition at line 720 of file qlabel.cpp.

References d, QWidget::ensurePolished(), QSize::height(), QWIDGETSIZE_MAX, QSize::rheight(), QSize::rwidth(), and QWidget::sizePolicy().

Referenced by sizeHint().

00721 {
00722     Q_D(const QLabel);
00723     if (d->valid_hints) {
00724         if (d->sizePolicy == sizePolicy())
00725             return d->msh;
00726     }
00727 
00728     ensurePolished();
00729     d->valid_hints = true;
00730     d->sh = d->sizeForWidth(-1); // wrap ? golden ratio : min doc size
00731     QSize msh(-1, -1);
00732 
00733     if (!d->doc) {
00734         msh = d->sh;
00735     } else {
00736         msh.rheight() = d->sizeForWidth(QWIDGETSIZE_MAX).height(); // height for one line
00737         msh.rwidth() = d->sizeForWidth(0).width(); // wrap ? size of biggest word : min doc size
00738         if (d->sh.height() < msh.height())
00739             msh.rheight() = d->sh.height();
00740     }
00741     d->msh = msh;
00742     d->sizePolicy = sizePolicy();
00743     return msh;
00744 }

Here is the call graph for this function:

void QLabel::setBuddy ( QWidget buddy  ) 

Sets this label's buddy to buddy.

When the user presses the shortcut key indicated by this label, the keyboard focus is transferred to the label's buddy widget.

The buddy mechanism is only available for QLabels that contain plain text in which one character is prefixed with an ampersand, '&'. This character is set as the shortcut key. See the {QShortcut::mnemonic}{QShortcut} documentation for details (to display an actual ampersand, use '&&').

In a dialog, you might create two data entry widgets and a label for each, and set up the geometry layout so each label is just to the left of its data entry widget (its "buddy"), for example:

    QLineEdit *nameEd  = new QLineEdit(this);
    QLabel    *nameLb  = new QLabel("&Name:", this);
    nameLb->setBuddy(nameEd);
    QLineEdit *phoneEd = new QLineEdit(this);
    QLabel    *phoneLb = new QLabel("&Phone:", this);
    phoneLb->setBuddy(phoneEd);
    // (layout setup not shown)

With the code above, the focus jumps to the Name field when the user presses Alt+N, and to the Phone field when the user presses Alt+P.

To unset a previously set buddy, call this function with buddy set to 0.

See also:
buddy(), setText(), QShortcut, setAlignment()

Definition at line 1050 of file qlabel.cpp.

References buddy(), d, and QWidget::releaseShortcut().

Referenced by BlockingClient::BlockingClient(), Client::Client(), FtpWindow::FtpWindow(), HttpWindow::HttpWindow(), QColorDialogPrivate::init(), QInputDialogPrivate::init(), LocationDialog::LocationDialog(), PreviewForm::PreviewForm(), QColorShower::QColorShower(), RegExpDialog::RegExpDialog(), QDesignerLabel::setBuddy(), QDesignerLabel::updateBuddy(), and WidgetGallery::WidgetGallery().

01051 {
01052     Q_D(QLabel);
01053     d->buddy = buddy;
01054     if (d->doc && !d->isRichText()) {
01055         releaseShortcut(d->shortcutId);
01056         d->shortcutId = -1;
01057         d->doc->setPlainText(d->text); // restore the old text
01058         if (buddy)
01059             d->updateShortcut(); // grab new shortcut
01060         d->updateLabel();
01061     }
01062 }

Here is the call graph for this function:

QWidget * QLabel::buddy (  )  const

Returns this label's buddy, or 0 if no buddy is currently set.

See also:
setBuddy()

Definition at line 1071 of file qlabel.cpp.

References d.

Referenced by Q3AccessibleDisplay::navigate(), QAccessibleDisplay::navigate(), QAccessibleDisplay::relationTo(), Q3AccessibleDisplay::relationTo(), and setBuddy().

01072 {
01073     Q_D(const QLabel);
01074     return d->buddy;
01075 }

int QLabel::heightForWidth ( int  w  )  const [virtual]

Reimplemented from QWidget.

Definition at line 638 of file qlabel.cpp.

References d, and QWidget::heightForWidth().

00639 {
00640     Q_D(const QLabel);
00641     if (d->doc)
00642         return d->sizeForWidth(w).height();
00643     return QWidget::heightForWidth(w);
00644 }

Here is the call graph for this function:

bool QLabel::openExternalLinks (  )  const

Definition at line 661 of file qlabel.cpp.

References d.

00662 {
00663     Q_D(const QLabel);
00664     return d->openExternalLinks;
00665 }

void QLabel::setOpenExternalLinks ( bool  open  ) 

Definition at line 667 of file qlabel.cpp.

References d.

Referenced by QMessageBoxPrivate::init(), QMessageBox::setInformativeText(), and VersionDialog::VersionDialog().

00668 {
00669     Q_D(QLabel);
00670     d->openExternalLinks = open;
00671     if (d->control)
00672         d->control->setOpenExternalLinks(open);
00673 }

void QLabel::setTextInteractionFlags ( Qt::TextInteractionFlags  flags  ) 

Definition at line 687 of file qlabel.cpp.

References Qt::ClickFocus, d, Qt::LinksAccessibleByKeyboard, Qt::NoFocus, QWidget::setFocusPolicy(), Qt::StrongFocus, and Qt::TextSelectableByKeyboard.

Referenced by QMessageBoxPrivate::init(), and QMessageBox::setInformativeText().

00688 {
00689     Q_D(QLabel);
00690     d->textInteractionFlags = flags;
00691     if (flags & Qt::LinksAccessibleByKeyboard)
00692         setFocusPolicy(Qt::StrongFocus);
00693     else if (flags & Qt::TextSelectableByKeyboard)
00694         setFocusPolicy(Qt::ClickFocus);
00695     else
00696         setFocusPolicy(Qt::NoFocus);
00697     if (d->control)
00698         d->control->setTextInteractionFlags(flags);
00699 }

Here is the call graph for this function:

Qt::TextInteractionFlags QLabel::textInteractionFlags (  )  const

Definition at line 701 of file qlabel.cpp.

References d.

00702 {
00703     Q_D(const QLabel);
00704     return d->textInteractionFlags;
00705 }

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

Definition at line 309 of file qlabel.cpp.

References d, QWidget::font(), QWidget::setMouseTracking(), and text().

Referenced by MainWindow::aboutQt(), Dialog::acceptConnection(), MainWindow::bold(), Sender::broadcastDatagram(), HttpWindow::cancelDownload(), MainWindow::center(), DropArea::clear(), FtpWindow::connectOrDisconnect(), Window::createDateTimeEdits(), Dialog::criticalMessage(), Dialog::displayError(), DropArea::dragEnterEvent(), DropArea::dropEvent(), Dialog::errorMessage(), PluginDialog::findPlugins(), FtpWindow::ftpCommandFinished(), HttpWindow::httpRequestFinished(), Dialog::informationMessage(), MainWindow::italic(), MainWindow::justify(), Q3Wizard::layOutTitleRow(), MainWindow::leftAlign(), qdesigner_internal::OldSignalSlotDialog::OldSignalSlotDialog(), CalculatorForm::on_inputSpinBox1_valueChanged(), CalculatorForm::on_inputSpinBox2_valueChanged(), Receiver::processPendingDatagrams(), QBalloonTip::QBalloonTip(), QLabel(), QTipLabel::QTipLabel(), Dialog::questionMessage(), QVFbRateDialog::rateChanged(), Client::readFortune(), MainWindow::redo(), RegExpDialog::RegExpDialog(), AnimationSaveWidget::reset(), MainWindow::rightAlign(), AnimationSaveWidget::save(), Server::Server(), Dialog::setColor(), Dialog::setDouble(), MainWindow::setDownloadLimit(), Dialog::setExistingDirectory(), Dialog::setFont(), Window::setFormatString(), Dialog::setInteger(), Dialog::setItem(), TransEditor::setLabel(), qdesigner_internal::RoleEditor::setLabel(), Q3ProgressDialog::setLabelText(), MainWindow::setLineSpacing(), Q3FileDialog::setMode(), setNum(), Dialog::setOpenFileName(), Dialog::setOpenFileNames(), MainWindow::setParagraphSpacing(), Dialog::setSaveFileName(), LCDRange::setText(), Dialog::setText(), setTextFormat(), Q3Wizard::setTitle(), MainWindow::setUploadLimit(), QFDProgressDialog::setWriteLabel(), Window::showFiles(), BlockingClient::showFortune(), Dialog::start(), Dialog::startTransfer(), AnimationSaveWidget::timerEvent(), AnimationSaveWidget::toggleRecord(), Dialog::updateClientProgress(), qdesigner_internal::AbstractPropertyGroup::updateEditorContents(), MainWindow::updateModel(), TrWindow::updateProgress(), Dialog::updateServerProgress(), SpreadSheet::updateStatus(), VersionDialog::VersionDialog(), Dialog::warningMessage(), and Zoomer::zoom().

00310 {
00311     Q_D(QLabel);
00312     if (d->text == text)
00313         return;
00314     d->clearContents();
00315     d->text = text;
00316     if (!d->doc) {
00317         d->doc = new QTextDocument(this);
00318         d->doc->setUndoRedoEnabled(false);
00319         d->doc->setDefaultFont(font());
00320     }
00321 
00322     if (d->isRichText()) {
00323         d->doc->setHtml(text);
00324         setMouseTracking(true);
00325         d->ensureTextControl();
00326     } else {
00327         d->doc->setPlainText(text);
00328         setMouseTracking(false);
00329 #ifndef QT_NO_SHORTCUT
00330         if (d->buddy)
00331             d->updateShortcut();
00332 #endif
00333     }
00334 
00335     d->updateLabel();
00336 }

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

Definition at line 364 of file qlabel.cpp.

References d, pixmap(), QWidget::QPixmap, and QPixmap::serialNumber().

Referenced by AnimationSaveWidget::AnimationSaveWidget(), AnimationSaveWidget::convertToMpeg(), decorationFromWidget(), DragWidget::DragWidget(), DragWidget::dropEvent(), DropArea::dropEvent(), ItemDialog::ItemDialog(), KAstTopLevel::KAstTopLevel(), DragWidget::mousePressEvent(), ImageViewer::open(), ImageComposer::recalculateResult(), MainWindow::setPixmap(), QHeaderViewPrivate::setupSectionIndicator(), AnimationSaveWidget::timerEvent(), AnimationSaveWidget::toggleRecord(), IconPreviewArea::updatePixmapLabels(), Screenshot::updateScreenshotLabel(), and VersionLabel::VersionLabel().

00365 {
00366     Q_D(QLabel);
00367     if (!d->pixmap || d->pixmap->serialNumber() != pixmap.serialNumber()) {
00368         d->clearContents();
00369         d->pixmap = new QPixmap(pixmap);
00370     }
00371 
00372     if (d->pixmap->depth() == 1 && !d->pixmap->mask())
00373         d->pixmap->setMask(*((QBitmap *)d->pixmap));
00374 
00375     d->updateLabel();
00376 }

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

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

The buddy shortcut, if any, is disabled.

See also:
picture(), setBuddy()

Definition at line 394 of file qlabel.cpp.

References d, and picture().

00395 {
00396     Q_D(QLabel);
00397     d->clearContents();
00398     d->picture = new QPicture(picture);
00399 
00400     d->updateLabel();
00401 }

void QLabel::setMovie ( QMovie movie  )  [slot]

Sets the label contents to movie. Any previous content is cleared. The label does NOT take ownership of the movie.

The buddy shortcut, if any, is disabled.

The label resizes itself if auto-resizing is enabled.

See also:
movie(), setBuddy()

Definition at line 1137 of file qlabel.cpp.

References _q_movieResized(), QObject::connect(), d, movie(), QMovie::Running, SIGNAL, SLOT, and QMovie::state().

Referenced by MoviePlayer::openFile().

01138 {
01139     Q_D(QLabel);
01140     d->clearContents();
01141 
01142     if (!movie)
01143         return;
01144 
01145     d->movie = movie;
01146     connect(movie, SIGNAL(resized(QSize)), this, SLOT(_q_movieResized(QSize)));
01147     connect(movie, SIGNAL(updated(QRect)), this, SLOT(_q_movieUpdated(QRect)));
01148 
01149     // Assume that if the movie is running,
01150     // resize/update signals will come soon enough
01151     if (movie->state() != QMovie::Running)
01152         d->updateLabel();
01153 }

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

Sets the label contents to plain text containing the textual representation of integer num. Any previous content is cleared. Does nothing if the integer's string representation is the same as the current contents of the label.

The buddy shortcut, if any, is disabled.

The label resizes itself if auto-resizing is enabled.

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

Definition at line 417 of file qlabel.cpp.

References QString::setNum(), and setText().

00418 {
00419     QString str;
00420     str.setNum(num);
00421     setText(str);
00422 }

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Sets the label contents to plain text containing the textual representation of double num. Any previous content is cleared. Does nothing if the double's string representation is the same as the current contents of the label.

The buddy shortcut, if any, is disabled.

The label resizes itself if auto-resizing is enabled.

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

Definition at line 439 of file qlabel.cpp.

References QString::setNum(), and setText().

00440 {
00441     QString str;
00442     str.setNum(num);
00443     setText(str);
00444 }

void QLabel::clear (  )  [slot]

Clears any label contents.

Definition at line 348 of file qlabel.cpp.

References d.

00349 {
00350     Q_D(QLabel);
00351     d->clearContents();
00352     d->updateLabel();
00353 }

void QLabel::linkActivated ( const QString link  )  [signal]

Since:
4.2
This signal is emitted when the user clicks a link. The URL referred to by the anchor is passed in link.

See also:
linkHovered()

void QLabel::linkHovered ( const QString link  )  [signal]

Since:
4.2
This signal is emitted when the user hovers over a link. The URL referred to by the anchor is passed in link.

See also:
linkActivated()

bool QLabel::event ( QEvent e  )  [protected, virtual]

Reimplemented from QFrame.

Definition at line 851 of file qlabel.cpp.

References d, QFrame::event(), QShortcutEvent::isAmbiguous(), Qt::NoFocus, QEvent::Resize, QWidget::setAttribute(), QEvent::Shortcut, Qt::ShortcutFocusReason, QShortcutEvent::shortcutId(), QEvent::StyleChange, QEvent::type(), type, w, Qt::WA_KeyboardFocusChange, and QWidget::window().

Referenced by DropArea::dragEnterEvent(), DropArea::dragLeaveEvent(), DropArea::dragMoveEvent(), DropArea::dropEvent(), and DragLabel::mousePressEvent().

00852 {
00853     Q_D(QLabel);
00854     QEvent::Type type = e->type();
00855 
00856 #ifndef QT_NO_SHORTCUT
00857     if (type == QEvent::Shortcut) {
00858         QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
00859         if (se->shortcutId() == d->shortcutId) {
00860             QWidget * w = d->buddy;
00861             QAbstractButton *button = qobject_cast<QAbstractButton *>(w);
00862             if (w->focusPolicy() != Qt::NoFocus)
00863                 w->setFocus(Qt::ShortcutFocusReason);
00864             if (button && !se->isAmbiguous())
00865                 button->animateClick();
00866             else
00867                 window()->setAttribute(Qt::WA_KeyboardFocusChange);
00868             return true;
00869         }
00870     } else
00871 #endif
00872     if (type == QEvent::Resize && d->doc) {
00873         d->textDirty = true;
00874     } else if (e->type() == QEvent::StyleChange) {
00875         d->updateLabel();
00876     }
00877 
00878     return QFrame::event(e);
00879 }

Here is the call graph for this function:

void QLabel::keyPressEvent ( QKeyEvent ev  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 843 of file qlabel.cpp.

References d.

00844 {
00845     Q_D(QLabel);
00846     d->sendControlEvent(ev);
00847 }

void QLabel::paintEvent ( QPaintEvent  )  [protected, virtual]

Reimplemented from QFrame.

Definition at line 883 of file qlabel.cpp.

References QRect::adjust(), Qt::AlignBottom, Qt::AlignHCenter, Qt::AlignRight, Qt::AlignVCenter, QBrush::color(), QPalette::color(), QWidget::contentsRect(), d, QIcon::Disabled, QFrame::drawFrame(), QStyle::drawItemPixmap(), QPainter::drawPicture(), QWidget::foregroundRole(), QPixmap::fromImage(), QStyle::generatedIconPixmap(), QRect::height(), Qt::IgnoreAspectRatio, QStyleOption::init(), QStyleOption::initFrom(), QWidget::isEnabled(), QWidget::layout(), QWidget::layoutDirection(), QPalette::light(), QAbstractTextDocumentLayout::PaintContext::palette, QWidget::palette(), QWidget::QPixmap, QPainter::restore(), QPainter::save(), QPainter::scale(), QPainter::setClipRect(), QPalette::setColor(), QStyle::SH_EtchDisabledText, QStyle::SH_UnderlineShortcut, QRect::size(), Qt::SmoothTransformation, QWidget::style(), QStyle::styleHint(), QPalette::Text, QRect::topLeft(), QPainter::translate(), QRect::translated(), QStyle::visualAlignment(), QRect::width(), QRect::x(), and QRect::y().

Referenced by VersionLabel::paintEvent(), and QTipLabel::paintEvent().

00884 {
00885     Q_D(QLabel);
00886     QStyle *style = QWidget::style();
00887     QPainter painter(this);
00888     drawFrame(&painter);
00889     QRect cr = contentsRect();
00890     cr.adjust(d->margin, d->margin, -d->margin, -d->margin);
00891     int align = QStyle::visualAlignment(layoutDirection(), QFlag(d->align));
00892 
00893 #ifndef QT_NO_MOVIE
00894     if (d->movie) {
00895         if (d->scaledcontents)
00896             style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap().scaled(cr.size()));
00897         else
00898             style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap());
00899     }
00900     else
00901 #endif
00902     if (d->doc) {
00903         const bool underline = (bool)style->styleHint(QStyle::SH_UnderlineShortcut, 0, this, 0);
00904 #ifndef QT_NO_SHORTCUT
00905         if (d->shortcutId != -1
00906             && underline != d->shortcutCursor.charFormat().fontUnderline()) {
00907                 QTextCharFormat fmt;
00908                 fmt.setFontUnderline(underline);
00909                 d->shortcutCursor.mergeCharFormat(fmt);
00910         }
00911 #endif
00912         d->ensureTextLayouted();
00913         QAbstractTextDocumentLayout *layout = d->doc->documentLayout();
00914         QRect lr = d->layoutRect();
00915 
00916         QAbstractTextDocumentLayout::PaintContext context;
00917         QStyleOption opt(0);
00918         opt.init(this);
00919 
00920         if (!isEnabled() && style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) {
00921             context.palette = palette();
00922             context.palette.setColor(QPalette::Text, context.palette.light().color());
00923             painter.save();
00924             painter.translate(lr.x() + 1, lr.y() + 1);
00925             painter.setClipRect(lr.translated(-lr.x() - 1, -lr.y() - 1));
00926             layout->draw(&painter, context);
00927             painter.restore();
00928         }
00929 
00930         // Adjust the palette
00931         context.palette = palette();
00932         if (foregroundRole() != QPalette::Text && isEnabled())
00933             context.palette.setColor(QPalette::Text, context.palette.color(foregroundRole()));
00934 
00935         painter.save();
00936         painter.translate(lr.topLeft());
00937         painter.setClipRect(lr.translated(-lr.x(), -lr.y()));
00938         if (d->control) {
00939             d->control->setPalette(context.palette);
00940             d->control->drawContents(&painter);
00941         } else {
00942             layout->draw(&painter, context);
00943         }
00944         painter.restore();
00945     } else
00946 #ifndef QT_NO_PICTURE
00947     if (d->picture) {
00948         QRect br = d->picture->boundingRect();
00949         int rw = br.width();
00950         int rh = br.height();
00951         if (d->scaledcontents) {
00952             painter.save();
00953             painter.translate(cr.x(), cr.y());
00954             painter.scale((double)cr.width()/rw, (double)cr.height()/rh);
00955             painter.drawPicture(-br.x(), -br.y(), *d->picture);
00956             painter.restore();
00957         } else {
00958             int xo = 0;
00959             int yo = 0;
00960             if (align & Qt::AlignVCenter)
00961                 yo = (cr.height()-rh)/2;
00962             else if (align & Qt::AlignBottom)
00963                 yo = cr.height()-rh;
00964             if (align & Qt::AlignRight)
00965                 xo = cr.width()-rw;
00966             else if (align & Qt::AlignHCenter)
00967                 xo = (cr.width()-rw)/2;
00968             painter.drawPicture(cr.x()+xo-br.x(), cr.y()+yo-br.y(), *d->picture);
00969         }
00970     } else
00971 #endif
00972     if (d->pixmap && !d->pixmap->isNull()) {
00973         QPixmap pix;
00974         if (d->scaledcontents) {
00975             if (!d->scaledpixmap || d->scaledpixmap->size() != cr.size()) {
00976                 if (!d->cachedimage)
00977                     d->cachedimage = new QImage(d->pixmap->toImage());
00978                 delete d->scaledpixmap;
00979                 d->scaledpixmap = new QPixmap(QPixmap::fromImage(d->cachedimage->scaled(cr.size(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation)));
00980             }
00981             pix = *d->scaledpixmap;
00982         } else
00983             pix = *d->pixmap;
00984         QStyleOption opt;
00985         opt.initFrom(this);
00986         if (!isEnabled())
00987             pix = style->generatedIconPixmap(QIcon::Disabled, pix, &opt);
00988         style->drawItemPixmap(&painter, cr, align, pix);
00989     }
00990 }

Here is the call graph for this function:

void QLabel::changeEvent ( QEvent ev  )  [protected, virtual]

Reimplemented from QFrame.

Definition at line 1248 of file qlabel.cpp.

References QEvent::ApplicationFontChange, QFrame::changeEvent(), d, QWidget::font(), QEvent::FontChange, QWidget::palette(), QEvent::PaletteChange, and QEvent::type().

01249 {
01250     Q_D(QLabel);
01251     if(ev->type() == QEvent::FontChange || ev->type() == QEvent::ApplicationFontChange) {
01252         if (d->doc) {
01253             d->doc->setDefaultFont(font());
01254             d->updateLabel();
01255         }
01256     } else if (ev->type() == QEvent::PaletteChange && d->control) {
01257         d->control->setPalette(palette());
01258     }
01259     QFrame::changeEvent(ev);
01260 }

Here is the call graph for this function:

void QLabel::mousePressEvent ( QMouseEvent ev  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 748 of file qlabel.cpp.

References d, and QEvent::ignore().

00749 {
00750     Q_D(QLabel);
00751     if (!d->doc) {
00752         ev->ignore();
00753         return;
00754     }
00755 
00756     d->sendControlEvent(ev);
00757 }

Here is the call graph for this function:

void QLabel::mouseMoveEvent ( QMouseEvent ev  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 761 of file qlabel.cpp.

References d, and QEvent::ignore().

00762 {
00763     Q_D(QLabel);
00764     if (!d->doc) {
00765         ev->ignore();
00766         return;
00767     }
00768 
00769     d->sendControlEvent(ev);
00770 }

Here is the call graph for this function:

void QLabel::mouseReleaseEvent ( QMouseEvent ev  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 774 of file qlabel.cpp.

References d, and QEvent::ignore().

00775 {
00776     Q_D(QLabel);
00777     if (!d->doc) {
00778         ev->ignore();
00779         return;
00780     }
00781 
00782     d->sendControlEvent(ev);
00783 }

Here is the call graph for this function:

void QLabel::contextMenuEvent ( QContextMenuEvent ev  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 787 of file qlabel.cpp.

References QEvent::accept(), d, QMenu::exec(), QContextMenuEvent::globalPos(), QEvent::ignore(), and QContextMenuEvent::pos().

00788 {
00789 #ifdef QT_NO_CONTEXTMENU
00790     Q_UNUSED(ev);
00791 #else
00792     Q_D(QLabel);
00793     if (!d->doc) {
00794         ev->ignore();
00795         return;
00796     }
00797     QMenu *menu = d->createStandardContextMenu(ev->pos());
00798     if (!menu) {
00799         ev->ignore();
00800         return;
00801     }
00802     ev->accept();
00803     menu->exec(ev->globalPos());
00804     delete menu;
00805 #endif
00806 }

Here is the call graph for this function:

void QLabel::focusInEvent ( QFocusEvent ev  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 811 of file qlabel.cpp.

References d, and QWidget::focusInEvent().

00812 {
00813     Q_D(QLabel);
00814     if (d->doc) {
00815         d->ensureTextControl();
00816         d->sendControlEvent(ev);
00817     }
00818     QFrame::focusInEvent(ev);
00819 }

Here is the call graph for this function:

void QLabel::focusOutEvent ( QFocusEvent ev  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 824 of file qlabel.cpp.

References d, and QWidget::focusOutEvent().

00825 {
00826     Q_D(QLabel);
00827     d->sendControlEvent(ev);
00828     QFrame::focusOutEvent(ev);
00829 }

Here is the call graph for this function:

bool QLabel::focusNextPrevChild ( bool  next  )  [protected, virtual]

Reimplemented from QWidget.

Definition at line 833 of file qlabel.cpp.

References d, and QWidget::focusNextPrevChild().

00834 {
00835     Q_D(QLabel);
00836     if (d->control && d->control->setFocusToNextOrPreviousAnchor(next))
00837         return true;
00838     return QFrame::focusNextPrevChild(next);
00839 }

Here is the call graph for this function:

QLabel::Q_PRIVATE_SLOT ( d_func()  ,
void   _q_movieUpdated(const QRect &) 
) [private]

void QLabel::_q_movieResized ( const QSize  )  [private]

Referenced by setMovie().

void void QLabel::_q_linkHovered ( const QString  )  [private]


Friends And Related Function Documentation

friend class QMessageBoxPrivate [friend]

Definition at line 147 of file qlabel.h.


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 18:07:55 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1