1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the widgets module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
33
#include "qdrawutil.h"
38
#include "qapplication.h"
39
#include "qtextdocument.h"
40
#include "qabstractbutton.h"
42
#include "qstyleoption.h"
45
#include "../text/qtextdocumentlayout_p.h"
47
class QLabelPrivate : public QFramePrivate
49
Q_DECLARE_PUBLIC(QLabel)
52
: img(0), pix(0), valid_hints(false), margin(0)
58
QSize sizeForWidth(int w) const;
60
QImage* img; // for scaled contents
61
QPixmap* pix; // for scaled contents
64
mutable bool valid_hints;
73
void movieUpdated(const QRect&);
74
void movieResized(const QSize&);
76
QPointer<QWidget> lbuddy;
80
uint scaledcontents :1;
81
Qt::TextFormat textformat;
82
#ifndef QT_NO_RICHTEXT
89
\brief The QLabel widget provides a text or image display.
95
QLabel is used for displaying text or an image. No user
96
interaction functionality is provided. The visual appearance of
97
the label can be configured in various ways, and it can be used
98
for specifying a focus mnemonic key for another widget.
100
A QLabel can contain any of the following content types:
103
\header \o Content \o Setting
105
\o Pass a QString to setText().
107
\o Pass a QString that contains rich text to setText().
109
\o Pass a QPixmap to setPixmap().
111
\o Pass a QMovie to setMovie().
113
\o Pass an \e int or a \e double to setNum(), which converts
114
the number to plain text.
116
\o The same as an empty plain text. This is the default. Set
120
When the content is changed using any of these functions, any
121
previous content is cleared.
123
The look of a QLabel can be tuned in several ways. All the
124
settings of QFrame are available for specifying a widget frame.
125
The positioning of the content within the QLabel widget area can
126
be tuned with setAlignment() and setIndent(). Text content can
127
also wrap lines along word bounderies with setWordWrap(). For
128
example, this code sets up a sunken panel with a two-line text in
129
the bottom right corner (both lines being flush with the right
133
QLabel *label = new QLabel(this);
134
label->setFrameStyle(QFrame::Panel | QFrame::Sunken);
135
label->setText("first line\nsecond line");
136
label->setAlignment(Qt::AlignBottom | Qt::AlignRight);
139
A QLabel is often used as a label for an interactive widget. For
140
this use QLabel provides a useful mechanism for adding an
141
mnemonic (see QKeysequence) that will set the keyboard focus to
142
the other widget (called the QLabel's "buddy"). For example:
144
QLineEdit* phoneEdit = new QLineEdit(this);
145
QLabel* phoneLabel = new QLabel("&Phone:", this);
146
phoneLabel->setBuddy(phoneEdit);
149
In this example, keyboard focus is transferred to the label's
150
buddy (the QLineEdit) when the user presses Alt+P. If the buddy
151
was a button (inheriting from QAbstractButton), triggering the
152
mnemonic would emulate a button click.
154
\inlineimage macintosh-label.png Screenshot in Macintosh style
155
\inlineimage windows-label.png Screenshot in Windows style
157
\sa QLineEdit, QTextEdit, QPixmap, QMovie,
158
{fowler}{GUI Design Handbook: Label}
161
#ifndef QT_NO_PICTURE
163
Returns the label's picture or 0 if the label doesn't have a
167
const QPicture *QLabel::picture() const
176
Constructs an empty label.
178
The \a parent and widget flag \a f, arguments are passed
179
to the QFrame constructor.
181
\sa setAlignment(), setFrameStyle(), setIndent()
183
QLabel::QLabel(QWidget *parent, Qt::WFlags f)
184
: QFrame(*new QLabelPrivate(), parent, f)
191
Constructs a label that displays the text, \a text.
193
The \a parent and widget flag \a f, arguments are passed
194
to the QFrame constructor.
196
\sa setText(), setAlignment(), setFrameStyle(), setIndent()
198
QLabel::QLabel(const QString &text, QWidget *parent, Qt::WFlags f)
199
: QFrame(*new QLabelPrivate(), parent, f)
209
Constructs an empty label.
211
The \a parent, \a name and widget flag \a f, arguments are passed
212
to the QFrame constructor.
214
\sa setAlignment(), setFrameStyle(), setIndent()
217
QLabel::QLabel(QWidget *parent, const char *name, Qt::WFlags f)
218
: QFrame(*new QLabelPrivate(), parent, f)
228
Constructs a label that displays the text, \a text.
230
The \a parent, \a name and widget flag \a f, arguments are passed
231
to the QFrame constructor.
233
\sa setText(), setAlignment(), setFrameStyle(), setIndent()
236
QLabel::QLabel(const QString &text, QWidget *parent, const char *name,
238
: QFrame(*new QLabelPrivate(), parent, f)
249
Constructs a label that displays the text \a text. The label has a
250
buddy widget, \a buddy.
252
If the \a text contains an underlined letter (a letter preceded by
253
an ampersand, \&), and the text is in plain text format, when the
254
user presses Alt+ the underlined letter, focus is passed to the
257
The \a parent, \a name and widget flag, \a f, arguments are passed
258
to the QFrame constructor.
260
\sa setText(), setBuddy(), setAlignment(), setFrameStyle(),
263
QLabel::QLabel(QWidget *buddy, const QString &text,
264
QWidget *parent, const char *name, Qt::WFlags f)
265
: QFrame(*new QLabelPrivate(), parent, f)
287
void QLabelPrivate::init()
296
#ifndef QT_NO_PICTURE
299
align = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextExpandTabs;
301
scaledcontents = false;
302
textformat = Qt::AutoText;
303
#ifndef QT_NO_RICHTEXT
307
q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
312
\property QLabel::text
313
\brief the label's text
315
If no text has been set this will return an empty string. Setting
316
the text clears any previous content, unless they are the same.
318
The text will be interpreted either as a plain text or as a rich
319
text, depending on the text format setting; see setTextFormat().
320
The default setting is \c Qt::AutoText, i.e. QLabel will try to
321
auto-detect the format of the text set.
323
If the text is interpreted as a plain text and a buddy has been
324
set, the buddy mnemonic key is updated from the new text.
326
The label resizes itself if auto-resizing is enabled.
328
Note that Qlabel is well-suited to display small rich text
329
documents, i.e. those small documents that get their document
330
specific settings (font, text color, link color) from the label's
331
palette and font properties. For large documents, use QTextEdit
332
in read-only mode instead. QTextEdit will flicker less on resize
333
and can also provide a scrollbar when necessary.
335
\sa setTextFormat(), setBuddy(), alignment
338
void QLabel::setText(const QString &text)
341
if (d->ltext == text)
345
#ifndef QT_NO_RICHTEXT
346
if (d->textformat == Qt::RichText
347
|| ((d->textformat == Qt::AutoText) && Qt::mightBeRichText(d->ltext))) {
349
d->doc = new QTextDocument();
350
d->doc->setUndoRedoEnabled(false);
351
d->doc->setDefaultFont(font());
352
d->doc->setHtml(d->ltext);
359
QString QLabel::text() const
366
Clears any label contents.
377
\property QLabel::pixmap
378
\brief the label's pixmap
380
If no pixmap has been set this will return an invalid pixmap.
382
Setting the pixmap clears any previous content. The buddy
383
shortcut, if any, is disabled.
385
void QLabel::setPixmap(const QPixmap &pixmap)
388
if (!d->lpixmap || d->lpixmap->serialNumber() != pixmap.serialNumber()) {
390
d->lpixmap = new QPixmap(pixmap);
393
if (d->lpixmap->depth() == 1 && !d->lpixmap->mask())
394
d->lpixmap->setMask(*((QBitmap *)d->lpixmap));
399
const QPixmap *QLabel::pixmap() const
405
#ifndef QT_NO_PICTURE
407
Sets the label contents to \a picture. Any previous content is
410
The buddy shortcut, if any, is disabled.
412
\sa picture(), setBuddy()
415
void QLabel::setPicture(const QPicture &picture)
419
d->lpicture = new QPicture(picture);
423
#endif // QT_NO_PICTURE
426
Sets the label contents to plain text containing the textual
427
representation of integer \a num. Any previous content is cleared.
428
Does nothing if the integer's string representation is the same as
429
the current contents of the label.
431
The buddy shortcut, if any, is disabled.
433
The label resizes itself if auto-resizing is enabled.
435
\sa setText(), QString::setNum(), setBuddy()
438
void QLabel::setNum(int num)
448
Sets the label contents to plain text containing the textual
449
representation of double \a num. Any previous content is cleared.
450
Does nothing if the double's string representation is the same as
451
the current contents of the label.
453
The buddy shortcut, if any, is disabled.
455
The label resizes itself if auto-resizing is enabled.
457
\sa setText(), QString::setNum(), setBuddy()
460
void QLabel::setNum(double num)
468
\property QLabel::alignment
469
\brief the alignment of the label's contents
474
void QLabel::setAlignment(Qt::Alignment alignment)
477
if (alignment == (d->align & (Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask)))
479
d->align = (d->align & ~(Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask))
480
| (alignment & (Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask));
487
Use setAlignment(Qt::Alignment) instead.
489
If \a alignment specifies text flags as well, use setTextFormat()
492
void QLabel::setAlignment(int alignment)
495
d->align = alignment & ~(Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask|Qt::TextWordWrap);
498
d->align |= Qt::TextShowMnemonic;
500
setAlignment(Qt::Alignment(QFlag(alignment)));
504
Qt::Alignment QLabel::alignment() const
507
return QFlag(d->align & (Qt::AlignVertical_Mask|Qt::AlignHorizontal_Mask));
512
\property QLabel::wordWrap
513
\brief the label's word-wrapping policy
515
If this property is true then label text is wrapped where
516
necessary at word-breaks; otherwise it is not wrapped at all.
518
void QLabel::setWordWrap(bool on)
522
d->align |= Qt::TextWordWrap;
524
d->align &= ~Qt::TextWordWrap;
529
bool QLabel::wordWrap() const
532
return d->align & Qt::TextWordWrap;
536
\property QLabel::indent
537
\brief the label's text indent in pixels
539
If a label displays text, the indent applies to the left edge if
540
alignment() is \c Qt::AlignLeft, to the right edge if alignment() is
541
\c Qt::AlignRight, to the top edge if alignment() is \c Qt::AlignTop, and
542
to to the bottom edge if alignment() is \c Qt::AlignBottom.
544
If indent is negative, or if no indent has been set, the label
545
computes the effective indent as follows: If frameWidth() is 0,
546
the effective indent becomes 0. If frameWidth() is greater than 0,
547
the effective indent becomes half the width of the "x" character
548
of the widget's current font().
550
\sa alignment, margin, frameWidth(), font()
553
void QLabel::setIndent(int indent)
556
d->extraMargin = indent;
560
int QLabel::indent() const
563
return d->extraMargin;
568
\property QLabel::margin
569
\brief the width of the margin
571
The margin is the distance between the innermost pixel of the
572
frame and the outermost pixel of contents.
574
The default margin is 0.
578
int QLabel::margin() const
584
void QLabel::setMargin(int margin)
587
if (d->margin == margin)
594
Returns the size that will be used if the width of the label is \a
595
w. If \a w is -1, the sizeHint() is returned.
597
QSize QLabelPrivate::sizeForWidth(int w) const
600
QSize contentsMargin(leftmargin + rightmargin, topmargin + bottommargin);
601
w -= contentsMargin.width();
603
QPixmap *pix = lpixmap;
604
#ifndef QT_NO_PICTURE
605
QPicture *pic = lpicture;
610
QMovie *mov = lmovie;
614
int hextra = 2 * margin;
616
QFontMetrics fm(q->fontMetrics());
617
int xw = fm.width('x');
618
if (!mov && !pix && !pic) {
620
if (m < 0 && frameWidth) // no indent, but we do have a frame
621
m = (xw / 2 - margin) * 2;
623
int align = QStyle::visualAlignment(q->layoutDirection(), QFlag(this->align));
624
if ((align & Qt::AlignLeft) || (align & Qt::AlignRight))
626
if ((align & Qt::AlignTop) || (align & Qt::AlignBottom))
633
#ifndef QT_NO_PICTURE
635
br = pic->boundingRect();
639
br = mov->currentPixmap().rect();
641
#ifndef QT_NO_RICHTEXT
643
QTextDocumentLayout *layout = qobject_cast<QTextDocumentLayout *>(doc->documentLayout());
645
if (align & Qt::TextWordWrap) {
647
doc->setPageSize(QSize(w-hextra, INT_MAX));
649
layout->adjustSize();
651
doc->setPageSize(QSize(0, 100000));
653
br = QRect(QPoint(0, 0), layout->documentSize().toSize());
657
bool tryWidth = (w < 0) && (align & Qt::TextWordWrap);
663
QString text = q->text();
664
br = fm.boundingRect(0, 0, w ,2000, align, text);
665
if (tryWidth && br.height() < 4*fm.lineSpacing() && br.width() > w/2)
666
br = fm.boundingRect(0, 0, w/2, 2000, align, text);
667
if (tryWidth && br.height() < 2*fm.lineSpacing() && br.width() > w/4)
668
br = fm.boundingRect(0, 0, w/4, 2000, align, text);
670
int wid = br.width() + hextra;
671
int hei = br.height() + vextra;
673
return QSize(wid, hei) + contentsMargin;
681
int QLabel::heightForWidth(int w) const
685
#ifndef QT_NO_RICHTEXT
688
(d->align & Qt::TextWordWrap))
689
return d->sizeForWidth(w).height();
690
return QWidget::heightForWidth(w);
697
QSize QLabel::sizeHint() const
701
(void) QLabel::minimumSizeHint();
709
QSize QLabel::minimumSizeHint() const
716
d->valid_hints = true;
717
d->sh = d->sizeForWidth(-1);
721
#ifndef QT_NO_RICHTEXT
724
(d->align & Qt::TextWordWrap) == 0) {
727
// think about caching these for performance
728
sz.rwidth() = d->sizeForWidth(0).width();
729
sz.rheight() = d->sizeForWidth(QWIDGETSIZE_MAX).height();
730
if (d->sh.height() < sz.height())
731
sz.rheight() = d->sh.height();
733
if (sizePolicy().horizontalPolicy() == QSizePolicy::Ignored)
735
if (sizePolicy().verticalPolicy() == QSizePolicy::Ignored)
743
bool QLabel::event(QEvent *e)
746
if (e->type() == QEvent::Shortcut) {
747
QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
748
if (se->shortcutId() == d->shortcutId) {
749
QWidget * w = d->lbuddy;
750
QAbstractButton *button = qobject_cast<QAbstractButton *>(w);
751
if (w->focusPolicy() != Qt::NoFocus)
752
w->setFocus(Qt::ShortcutFocusReason);
753
if (button && !se->isAmbiguous())
754
button->animateClick();
756
window()->setAttribute(Qt::WA_KeyboardFocusChange);
760
return QFrame::event(e);
765
void QLabel::paintEvent(QPaintEvent *)
768
QStyle *style = QWidget::style();
769
QPainter paint(this);
771
QRect cr = contentsRect();
772
cr.adjust(d->margin, d->margin, -d->margin, -d->margin);
777
#ifndef QT_NO_PICTURE
778
const QPicture *pic = picture();
783
const QMovie *mov = movie();
788
int align = QStyle::visualAlignment(layoutDirection(), QFlag(d->align));
790
if (!mov && !pix && !pic) {
792
if (m < 0 && frameWidth()) // no indent, but we do have a frame
793
m = fontMetrics().width('x') / 2 - d->margin;
795
if (align & Qt::AlignLeft)
796
cr.setLeft(cr.left() + m);
797
if (align & Qt::AlignRight)
798
cr.setRight(cr.right() - m);
799
if (align & Qt::AlignTop)
800
cr.setTop(cr.top() + m);
801
if (align & Qt::AlignBottom)
802
cr.setBottom(cr.bottom() - m);
808
QRect r = style->itemPixmapRect(cr, align, mov->currentPixmap());
809
// ### could resize movie frame at this point
810
paint.drawPixmap(r.x(), r.y(), mov->currentPixmap());
814
#ifndef QT_NO_RICHTEXT
816
QTextDocumentLayout *layout = qobject_cast<QTextDocumentLayout *>(d->doc->documentLayout());
818
d->doc->setPageSize(QSize(cr.width(), INT_MAX));
819
int rh = qRound(layout->documentSize().height());
821
if (align & Qt::AlignVCenter)
822
yo = (cr.height()-rh)/2;
823
else if (align & Qt::AlignBottom)
825
QAbstractTextDocumentLayout::PaintContext context;
828
if (!isEnabled() && style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) {
829
context.palette = palette();
830
context.palette.setColor(QPalette::Text, context.palette.light().color());
832
r.translate(-cr.x()-1, -cr.y()-yo-1);
834
paint.translate(cr.x()+1, cr.y()+yo+1);
835
paint.setClipRect(r);
836
layout->draw(&paint, context);
840
// QSimpleRichText always draws with QPalette::Text as with
841
// background mode Qt::PaletteBase. QLabel typically has
842
// background mode Qt::PaletteBackground, so we create a temporary
843
// color group with the text color adjusted.
844
context.palette = palette();
845
if (foregroundRole() != QPalette::Text && isEnabled())
846
context.palette.setColor(QPalette::Foreground, context.palette.color(foregroundRole()));
848
r.translate(-cr.x(), -cr.y()-yo);
850
paint.translate(cr.x(), cr.y()+yo);
851
paint.setClipRect(r);
852
layout->draw(&paint, context);
856
#ifndef QT_NO_PICTURE
858
QRect br = pic->boundingRect();
860
int rh = br.height();
861
if (d->scaledcontents) {
863
paint.translate(cr.x(), cr.y());
864
#ifndef QT_NO_TRANSFORMATIONS
865
paint.scale((double)cr.width()/rw, (double)cr.height()/rh);
867
paint.drawPicture(-br.x(), -br.y(), *pic);
872
if (align & Qt::AlignVCenter)
873
yo = (cr.height()-rh)/2;
874
else if (align & Qt::AlignBottom)
876
if (align & Qt::AlignRight)
878
else if (align & Qt::AlignHCenter)
879
xo = (cr.width()-rw)/2;
880
paint.drawPicture(cr.x()+xo-br.x(), cr.y()+yo-br.y(), *pic);
885
#ifndef QT_NO_IMAGE_SMOOTHSCALE
886
if (d->scaledcontents && !pix.isNull()) {
888
d->img = new QImage(d->lpixmap->toImage());
891
d->pix = new QPixmap;
892
if (d->pix->size() != cr.size())
893
*d->pix = QPixmap::fromImage(d->img->scaled(cr.width(), cr.height()));
899
if ((align & Qt::TextShowMnemonic) && !style->styleHint(QStyle::SH_UnderlineShortcut, &opt, this))
900
align |= Qt::TextHideMnemonic;
901
// ordinary text or pixmap label
904
pix = style->generatedIconPixmap(QIcon::Disabled, pix, &opt);
905
style->drawItemPixmap(&paint, cr, align, pix);
907
style->drawItemText(&paint, cr, align, palette(), isEnabled(), d->ltext);
915
Updates the label, but not the frame.
918
void QLabelPrivate::updateLabel()
922
QSizePolicy policy = q->sizePolicy();
923
bool wordWrap = align & Qt::TextWordWrap;
924
policy.setHeightForWidth(wordWrap);
925
if (policy != q->sizePolicy())
926
q->setSizePolicy(policy);
927
q->releaseShortcut(shortcutId);
929
#ifndef QT_NO_RICHTEXT
933
shortcutId = q->grabShortcut(QKeySequence::mnemonic(ltext));
936
int align = QStyle::visualAlignment(q->layoutDirection(), QFlag(this->align));
937
int flags = (wordWrap? 0 : Qt::TextSingleLine) | align;
938
flags |= (q->layoutDirection() == Qt::RightToLeft) ? QTextDocumentLayout::RTL : QTextDocumentLayout::LTR;
939
qobject_cast<QTextDocumentLayout *>(doc->documentLayout())->setBlockTextFlags(flags);
943
q->update(q->contentsRect());
947
Sets this label's buddy to \a buddy.
949
When the user presses the shortcut key indicated by this label,
950
the keyboard focus is transferred to the label's buddy widget.
952
The buddy mechanism is only available for QLabels that contain
953
plain text in which one letter is prefixed with an ampersand, \&.
954
This letter is set as the shortcut key. The letter is displayed
955
underlined, and the '\&' is not displayed (i.e. the \c Qt::TextShowMnemonic
956
alignment flag is turned on; see setAlignment()).
958
In a dialog, you might create two data entry widgets and a label
959
for each, and set up the geometry layout so each label is just to
960
the left of its data entry widget (its "buddy"), for example:
962
QLineEdit *nameEd = new QLineEdit(this);
963
QLabel *nameLb = new QLabel("&Name:", this);
964
nameLb->setBuddy(nameEd);
965
QLineEdit *phoneEd = new QLineEdit(this);
966
QLabel *phoneLb = new QLabel("&Phone:", this);
967
phoneLb->setBuddy(phoneEd);
968
// (layout setup not shown)
971
With the code above, the focus jumps to the Name field when the
972
user presses Alt+N, and to the Phone field when the user presses
975
To unset a previously set buddy, call this function with \a buddy
978
\sa buddy(), setText(), QShortcut, setAlignment()
981
void QLabel::setBuddy(QWidget *buddy)
985
d->align |= Qt::TextShowMnemonic;
987
d->align &= ~Qt::TextShowMnemonic;
996
Returns this label's buddy, or 0 if no buddy is currently set.
1001
QWidget * QLabel::buddy() const
1009
void QLabelPrivate::movieUpdated(const QRect& rect)
1012
if (lmovie && lmovie->isValid()) {
1013
QRect r = q->contentsRect();
1014
r = q->style()->itemPixmapRect(r, align, lmovie->currentPixmap());
1015
r.translate(rect.x(), rect.y());
1016
r.setWidth(qMin(r.width(), rect.width()));
1017
r.setHeight(qMin(r.height(), rect.height()));
1022
void QLabelPrivate::movieResized(const QSize& size)
1025
valid_hints = false;
1026
movieUpdated(QRect(QPoint(0,0), size));
1027
q->updateGeometry();
1031
Sets the label contents to \a movie. Any previous content is
1034
The buddy shortcut, if any, is disabled.
1036
The label resizes itself if auto-resizing is enabled.
1038
\sa movie(), setBuddy()
1041
void QLabel::setMovie(QMovie *movie)
1047
connect(movie, SIGNAL(resized(QSize)), this, SLOT(movieResized(QSize)));
1048
connect(movie, SIGNAL(updated(QRect)), this, SLOT(movieUpdated(QRect)));
1050
// Assume that if the movie is running,
1051
// resize/update signals will come soon enough
1052
if (movie->state() != QMovie::Running)
1056
#endif // QT_NO_MOVIE
1061
Clears any contents, without updating/repainting the label.
1064
void QLabelPrivate::clearContents()
1067
#ifndef QT_NO_RICHTEXT
1074
#ifndef QT_NO_PICTURE
1084
q->releaseShortcut(shortcutId);
1095
Returns a pointer to the label's movie, or 0 if no movie has been
1101
QMovie *QLabel::movie() const
1107
#endif // QT_NO_MOVIE
1110
\property QLabel::textFormat
1111
\brief the label's text format
1113
See the Qt::TextFormat enum for an explanation of the possible
1116
The default format is Qt::AutoText.
1121
Qt::TextFormat QLabel::textFormat() const
1124
return d->textformat;
1127
void QLabel::setTextFormat(Qt::TextFormat format)
1130
if (format != d->textformat) {
1131
d->textformat = format;
1132
QString t = d->ltext;
1143
void QLabel::changeEvent(QEvent *ev)
1146
if(ev->type() == QEvent::FontChange) {
1147
if (!d->ltext.isEmpty()) {
1148
#ifndef QT_NO_RICHTEXT
1150
d->doc->setDefaultFont(font());
1155
QFrame::changeEvent(ev);
1158
#ifndef QT_NO_IMAGE_SMOOTHSCALE
1160
\property QLabel::scaledContents
1161
\brief whether the label will scale its contents to fill all
1164
When enabled and the label shows a pixmap, it will scale the
1165
pixmap to fill the available space.
1167
This property's default is false.
1169
bool QLabel::hasScaledContents() const
1172
return d->scaledcontents;
1175
void QLabel::setScaledContents(bool enable)
1178
if ((bool)d->scaledcontents == enable)
1180
d->scaledcontents = enable;
1187
update(contentsRect());
1190
#endif // QT_NO_IMAGE_SMOOTHSCALE
1193
\fn void QLabel::setAlignment(Qt::AlignmentFlag flag)
1196
Without this function, a call to e.g. setAlignment(Qt::AlignTop)
1197
results in the \c QT3_SUPPORT function setAlignment(int) being called,
1198
rather than setAlignment(Qt::Alignment).
1202
#include "moc_qlabel.cpp"
1204
#endif // QT_NO_LABEL