Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qlabel.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qpainter.h"
5#include "qevent.h"
6#include "qdrawutil.h"
7#include "qapplication.h"
8#if QT_CONFIG(abstractbutton)
9#include "qabstractbutton.h"
10#endif
11#include "qstyle.h"
12#include "qstyleoption.h"
13#include <limits.h>
14#include "qclipboard.h"
15#include <qdebug.h>
16#include <qurl.h>
17#include "qlabel_p.h"
18#include "private/qstylesheetstyle_p.h"
19#include <qmath.h>
20
21#if QT_CONFIG(accessibility)
22#include <qaccessible.h>
23#endif
24
26
27using namespace Qt::StringLiterals;
28
30 : QFramePrivate(),
31 sh(),
32 msh(),
33 text(),
34 pixmap(),
35 scaledpixmap(),
36 cachedimage(),
37#ifndef QT_NO_PICTURE
38 picture(),
39#endif
40#if QT_CONFIG(movie)
41 movie(),
42#endif
43 control(nullptr),
44 shortcutCursor(),
45#ifndef QT_NO_CURSOR
46 cursor(),
47#endif
48#ifndef QT_NO_SHORTCUT
49 buddy(),
50 shortcutId(0),
51#endif
52 textformat(Qt::AutoText),
53 effectiveTextFormat(Qt::PlainText),
54 textInteractionFlags(Qt::LinksAccessibleByMouse),
55 sizePolicy(),
56 margin(0),
57 align(Qt::AlignLeft | Qt::AlignVCenter | Qt::TextExpandTabs),
58 indent(-1),
59 valid_hints(false),
60 scaledcontents(false),
61 textLayoutDirty(false),
62 textDirty(false),
63 isTextLabel(false),
64 hasShortcut(/*???*/),
65#ifndef QT_NO_CURSOR
66 validCursor(false),
67 onAnchor(false),
68#endif
69 openExternalLinks(false),
70 resourceProvider(nullptr)
71{
72}
73
75{
76}
77
155#ifndef QT_NO_PICTURE
174{
175 Q_D(const QLabel);
176 if (d->picture)
177 return *(d->picture);
178 return QPicture();
179}
180#endif // QT_NO_PICTURE
181
182
191QLabel::QLabel(QWidget *parent, Qt::WindowFlags f)
192 : QFrame(*new QLabelPrivate(), parent, f)
193{
194 Q_D(QLabel);
195 d->init();
196}
197
206QLabel::QLabel(const QString &text, QWidget *parent, Qt::WindowFlags f)
207 : QLabel(parent, f)
208{
209 setText(text);
210}
211
212
213
219{
220 Q_D(QLabel);
221 d->clearContents();
222}
223
225{
226 Q_Q(QLabel);
227
231}
232
233
264{
265 Q_D(QLabel);
266 if (d->text == text)
267 return;
268
269 QWidgetTextControl *oldControl = d->control;
270 d->control = nullptr;
271
272 d->clearContents();
273 d->text = text;
274 d->isTextLabel = true;
275 d->textDirty = true;
276 if (d->textformat == Qt::AutoText) {
277 if (Qt::mightBeRichText(d->text))
278 d->effectiveTextFormat = Qt::RichText;
279 else
280 d->effectiveTextFormat = Qt::PlainText;
281 } else {
282 d->effectiveTextFormat = d->textformat;
283 }
284
285 d->control = oldControl;
286
287 if (d->needTextControl()) {
288 d->ensureTextControl();
289 } else {
290 delete d->control;
291 d->control = nullptr;
292 }
293
294 if (d->effectiveTextFormat != Qt::PlainText) {
295 setMouseTracking(true);
296 } else {
297 // Note: mouse tracking not disabled intentionally
298 }
299
300#ifndef QT_NO_SHORTCUT
301 if (d->buddy)
302 d->updateShortcut();
303#endif
304
305 d->updateLabel();
306
307#if QT_CONFIG(accessibility)
308 if (accessibleName().isEmpty()) {
309 QAccessibleEvent event(this, QAccessible::NameChanged);
310 QAccessible::updateAccessibility(&event);
311 }
312#endif
313}
314
316{
317 Q_D(const QLabel);
318 return d->text;
319}
320
326{
327 Q_D(QLabel);
328 d->clearContents();
329 d->updateLabel();
330}
331
340{
341 Q_D(QLabel);
342 if (!d->pixmap || d->pixmap->cacheKey() != pixmap.cacheKey()) {
343 d->clearContents();
344 d->pixmap = pixmap;
345 }
346
347 d->updateLabel();
348}
349
351{
352 Q_D(const QLabel);
353 if (d->pixmap)
354 return *(d->pixmap);
355 return QPixmap();
356}
357
375#ifndef QT_NO_PICTURE
386{
387 Q_D(QLabel);
388 d->clearContents();
389 d->picture = picture;
390
391 d->updateLabel();
392}
393#endif // QT_NO_PICTURE
394
407{
408 QString str;
409 str.setNum(num);
410 setText(str);
411}
412
426void QLabel::setNum(double num)
427{
428 QString str;
429 str.setNum(num);
430 setText(str);
431}
432
443{
444 Q_D(QLabel);
446 return;
449
450 d->updateLabel();
451}
452
453
454Qt::Alignment QLabel::alignment() const
455{
456 Q_D(const QLabel);
458}
459
460
473{
474 Q_D(QLabel);
475 if (on)
476 d->align |= Qt::TextWordWrap;
477 else
478 d->align &= ~Qt::TextWordWrap;
479
480 d->updateLabel();
481}
482
484{
485 Q_D(const QLabel);
486 return d->align & Qt::TextWordWrap;
487}
488
510void QLabel::setIndent(int indent)
511{
512 Q_D(QLabel);
513 d->indent = indent;
514 d->updateLabel();
515}
516
517int QLabel::indent() const
518{
519 Q_D(const QLabel);
520 return d->indent;
521}
522
523
535int QLabel::margin() const
536{
537 Q_D(const QLabel);
538 return d->margin;
539}
540
541void QLabel::setMargin(int margin)
542{
543 Q_D(QLabel);
544 if (d->margin == margin)
545 return;
546 d->margin = margin;
547 d->updateLabel();
548}
549
555{
556 Q_Q(const QLabel);
557 if (q->minimumWidth() > 0)
558 w = qMax(w, q->minimumWidth());
560
561 QRect br;
562
563 int hextra = 2 * margin;
564 int vextra = hextra;
565 QFontMetrics fm = q->fontMetrics();
566
567 if (pixmap && !pixmap->isNull()) {
568 br = pixmap->rect();
569 br.setSize(pixmap->deviceIndependentSize().toSize());
570#ifndef QT_NO_PICTURE
571 } else if (picture && !picture->isNull()) {
572 br = picture->boundingRect();
573#endif
574#if QT_CONFIG(movie)
575 } else if (movie && !movie->currentPixmap().isNull()) {
576 br = movie->currentPixmap().rect();
577 br.setSize(movie->currentPixmap().deviceIndependentSize().toSize());
578#endif
579 } else if (isTextLabel) {
580 int align = QStyle::visualAlignment(textDirection(), QFlag(this->align));
581 // Add indentation
582 int m = indent;
583
584 if (m < 0 && q->frameWidth()) // no indent, but we do have a frame
585 m = fm.horizontalAdvance(u'x') - margin*2;
586 if (m > 0) {
588 hextra += m;
590 vextra += m;
591 }
592
593 if (control) {
595 const qreal oldTextWidth = control->textWidth();
596 // Calculate the length of document if w is the width
597 if (align & Qt::TextWordWrap) {
598 if (w >= 0) {
599 w = qMax(w-hextra-contentsMargin.width(), 0); // strip margin and indent
601 } else {
603 }
604 } else {
606 }
607
608 QSizeF controlSize = control->size();
609 br = QRect(QPoint(0, 0), QSize(qCeil(controlSize.width()), qCeil(controlSize.height())));
610
611 // restore state
612 control->setTextWidth(oldTextWidth);
613 } else {
614 // Turn off center alignment in order to avoid rounding errors for centering,
615 // since centering involves a division by 2. At the end, all we want is the size.
617 if (hasShortcut) {
620 opt.initFrom(q);
621 if (!q->style()->styleHint(QStyle::SH_UnderlineShortcut, &opt, q))
623 }
624
625 bool tryWidth = (w < 0) && (align & Qt::TextWordWrap);
626 if (tryWidth)
627 w = qMin(fm.averageCharWidth() * 80, q->maximumSize().width());
628 else if (w < 0)
629 w = 2000;
630 w -= (hextra + contentsMargin.width());
631 br = fm.boundingRect(0, 0, w ,2000, flags, text);
632 if (tryWidth && br.height() < 4*fm.lineSpacing() && br.width() > w/2)
633 br = fm.boundingRect(0, 0, w/2, 2000, flags, text);
634 if (tryWidth && br.height() < 2*fm.lineSpacing() && br.width() > w/4)
635 br = fm.boundingRect(0, 0, w/4, 2000, flags, text);
636 }
637 } else {
638 br = QRect(QPoint(0, 0), QSize(fm.averageCharWidth(), fm.lineSpacing()));
639 }
640
641 const QSize contentsSize(br.width() + hextra, br.height() + vextra);
642 return (contentsSize + contentsMargin).expandedTo(q->minimumSize());
643}
644
645
651{
652 Q_D(const QLabel);
653 if (d->isTextLabel)
654 return d->sizeForWidth(w).height();
656}
657
674{
675 Q_D(const QLabel);
676 return d->openExternalLinks;
677}
678
680{
681 Q_D(QLabel);
682 d->openExternalLinks = open;
683 if (d->control)
684 d->control->setOpenExternalLinks(open);
685}
686
699void QLabel::setTextInteractionFlags(Qt::TextInteractionFlags flags)
700{
701 Q_D(QLabel);
702 if (d->textInteractionFlags == flags)
703 return;
704 d->textInteractionFlags = flags;
709 else
711
712 if (d->needTextControl()) {
713 d->ensureTextControl();
714 } else {
715 delete d->control;
716 d->control = nullptr;
717 }
718
719 if (d->control)
720 d->control->setTextInteractionFlags(d->textInteractionFlags);
721}
722
723Qt::TextInteractionFlags QLabel::textInteractionFlags() const
724{
725 Q_D(const QLabel);
726 return d->textInteractionFlags;
727}
728
740{
741 Q_D(QLabel);
742 if (d->control) {
743 d->ensureTextPopulated();
744 QTextCursor cursor = d->control->textCursor();
745 cursor.setPosition(start);
747 d->control->setTextCursor(cursor);
748 }
749}
750
768{
769 Q_D(const QLabel);
770 if (d->control)
771 return d->control->textCursor().hasSelection();
772 return false;
773}
774
792{
793 Q_D(const QLabel);
794 if (d->control)
795 return d->control->textCursor().selectedText();
796 return QString();
797}
798
811{
812 Q_D(const QLabel);
813 if (d->control && d->control->textCursor().hasSelection())
814 return d->control->textCursor().selectionStart();
815 return -1;
816}
817
821{
822 Q_D(const QLabel);
823 if (!d->valid_hints)
825 return d->sh;
826}
827
832{
833 Q_D(const QLabel);
834 if (d->valid_hints) {
835 if (d->sizePolicy == sizePolicy())
836 return d->msh;
837 }
838
840 d->valid_hints = true;
841 d->sh = d->sizeForWidth(-1); // wrap ? golden ratio : min doc size
842 QSize msh(-1, -1);
843
844 if (!d->isTextLabel) {
845 msh = d->sh;
846 } else {
847 msh.rheight() = d->sizeForWidth(QWIDGETSIZE_MAX).height(); // height for one line
848 msh.rwidth() = d->sizeForWidth(0).width(); // wrap ? size of biggest word : min doc size
849 if (d->sh.height() < msh.height())
850 msh.rheight() = d->sh.height();
851 }
852 d->msh = msh;
853 d->sizePolicy = sizePolicy();
854 return msh;
855}
856
860{
861 Q_D(QLabel);
862 d->sendControlEvent(ev);
863}
864
868{
869 Q_D(QLabel);
870 d->sendControlEvent(ev);
871}
872
876{
877 Q_D(QLabel);
878 d->sendControlEvent(ev);
879}
880
881#ifndef QT_NO_CONTEXTMENU
885{
886 Q_D(QLabel);
887 if (!d->isTextLabel) {
888 ev->ignore();
889 return;
890 }
891 QMenu *menu = d->createStandardContextMenu(ev->pos());
892 if (!menu) {
893 ev->ignore();
894 return;
895 }
896 ev->accept();
898 menu->popup(ev->globalPos());
899}
900#endif // QT_NO_CONTEXTMENU
901
906{
907 Q_D(QLabel);
908 if (d->isTextLabel) {
909 d->ensureTextControl();
910 d->sendControlEvent(ev);
911 }
913}
914
919{
920 Q_D(QLabel);
921 if (d->control) {
922 d->sendControlEvent(ev);
923 QTextCursor cursor = d->control->textCursor();
924 Qt::FocusReason reason = ev->reason();
925 if (reason != Qt::ActiveWindowFocusReason
926 && reason != Qt::PopupFocusReason
927 && cursor.hasSelection()) {
928 cursor.clearSelection();
929 d->control->setTextCursor(cursor);
930 }
931 }
932
934}
935
939{
940 Q_D(QLabel);
941 if (d->control && d->control->setFocusToNextOrPreviousAnchor(next))
942 return true;
944}
945
949{
950 Q_D(QLabel);
951 d->sendControlEvent(ev);
952}
953
957{
958 Q_D(QLabel);
959 QEvent::Type type = e->type();
960
961#ifndef QT_NO_SHORTCUT
962 if (type == QEvent::Shortcut) {
963 QShortcutEvent *se = static_cast<QShortcutEvent *>(e);
964 if (se->shortcutId() == d->shortcutId) {
965 QWidget *w = d->buddy;
966 if (!w)
967 return QFrame::event(e);
968 if (w->focusPolicy() != Qt::NoFocus)
969 w->setFocus(Qt::ShortcutFocusReason);
970#if QT_CONFIG(abstractbutton)
971 QAbstractButton *button = qobject_cast<QAbstractButton *>(w);
972 if (button && !se->isAmbiguous())
974 else
975#endif
977 return true;
978 }
979 } else
980#endif
981 if (type == QEvent::Resize) {
982 if (d->control)
983 d->textLayoutDirty = true;
984 } else if (e->type() == QEvent::StyleChange
985#ifdef Q_OS_MAC
986 || e->type() == QEvent::MacSizeChange
987#endif
988 ) {
989 d->setLayoutItemMargins(QStyle::SE_LabelLayoutItem);
990 d->updateLabel();
991 } else if (type == QEvent::Polish) {
992 if (d->needTextControl())
993 d->ensureTextControl();
994 }
995
996 return QFrame::event(e);
997}
998
1002{
1003 Q_D(QLabel);
1005 QPainter painter(this);
1007 QRect cr = contentsRect();
1008 cr.adjust(d->margin, d->margin, -d->margin, -d->margin);
1009 int align = QStyle::visualAlignment(d->isTextLabel ? d->textDirection()
1010 : layoutDirection(), QFlag(d->align));
1011
1012#if QT_CONFIG(movie)
1013 if (d->movie && !d->movie->currentPixmap().isNull()) {
1014 if (d->scaledcontents)
1015 style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap().scaled(cr.size()));
1016 else
1017 style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap());
1018 }
1019 else
1020#endif
1021 if (d->isTextLabel) {
1022 QRectF lr = d->layoutRect().toAlignedRect();
1024 opt.initFrom(this);
1025#ifndef QT_NO_STYLE_STYLESHEET
1026 if (QStyleSheetStyle* cssStyle = qt_styleSheet(style))
1027 cssStyle->styleSheetPalette(this, &opt, &opt.palette);
1028#endif
1029 if (d->control) {
1030#ifndef QT_NO_SHORTCUT
1031 const bool underline = static_cast<bool>(style->styleHint(QStyle::SH_UnderlineShortcut,
1032 nullptr, this, nullptr));
1033 if (d->shortcutId != 0
1034 && underline != d->shortcutCursor.charFormat().fontUnderline()) {
1036 fmt.setFontUnderline(underline);
1037 d->shortcutCursor.mergeCharFormat(fmt);
1038 }
1039#endif
1040 d->ensureTextLayouted();
1041
1043 // Adjust the palette
1044 context.palette = opt.palette;
1045
1047 context.palette.setColor(QPalette::Text, context.palette.color(foregroundRole()));
1048
1049 painter.save();
1051 painter.setClipRect(lr.translated(-lr.x(), -lr.y()));
1052 d->control->setPalette(context.palette);
1053 d->control->drawContents(&painter, QRectF(), this);
1054 painter.restore();
1055 } else {
1056 int flags = align | (d->textDirection() == Qt::LeftToRight ? Qt::TextForceLeftToRight
1058 if (d->hasShortcut) {
1062 }
1064 }
1065 } else
1066#ifndef QT_NO_PICTURE
1067 if (d->picture) {
1068 QRect br = d->picture->boundingRect();
1069 int rw = br.width();
1070 int rh = br.height();
1071 if (d->scaledcontents) {
1072 painter.save();
1073 painter.translate(cr.x(), cr.y());
1074 painter.scale((double)cr.width()/rw, (double)cr.height()/rh);
1075 painter.drawPicture(-br.x(), -br.y(), *d->picture);
1076 painter.restore();
1077 } else {
1078 int xo = 0;
1079 int yo = 0;
1080 if (align & Qt::AlignVCenter)
1081 yo = (cr.height()-rh)/2;
1082 else if (align & Qt::AlignBottom)
1083 yo = cr.height()-rh;
1084 if (align & Qt::AlignRight)
1085 xo = cr.width()-rw;
1086 else if (align & Qt::AlignHCenter)
1087 xo = (cr.width()-rw)/2;
1088 painter.drawPicture(cr.x()+xo-br.x(), cr.y()+yo-br.y(), *d->picture);
1089 }
1090 } else
1091#endif
1092 if (d->pixmap && !d->pixmap->isNull()) {
1093 QPixmap pix;
1094 const qreal dpr = devicePixelRatio();
1095 if (d->scaledcontents || dpr != d->pixmap->devicePixelRatio()) {
1096 QSize scaledSize = d->scaledcontents ? (cr.size() * dpr)
1097 : (d->pixmap->size() * (dpr / d->pixmap->devicePixelRatio()));
1098 if (!d->scaledpixmap || d->scaledpixmap->size() != scaledSize) {
1099 if (!d->cachedimage)
1100 d->cachedimage = d->pixmap->toImage();
1101 d->scaledpixmap.reset();
1102 QImage scaledImage =
1103 d->cachedimage->scaled(scaledSize,
1105 d->scaledpixmap = QPixmap::fromImage(std::move(scaledImage));
1106 d->scaledpixmap->setDevicePixelRatio(dpr);
1107 }
1108 pix = *d->scaledpixmap;
1109 } else
1110 pix = *d->pixmap;
1112 opt.initFrom(this);
1113 if (!isEnabled())
1115 style->drawItemPixmap(&painter, cr, align, pix);
1116 }
1117}
1118
1119
1125{
1126 Q_Q(QLabel);
1127 valid_hints = false;
1128
1129 if (isTextLabel) {
1130 QSizePolicy policy = q->sizePolicy();
1131 const bool wrap = align & Qt::TextWordWrap;
1133 if (policy != q->sizePolicy()) // ### should be replaced by WA_WState_OwnSizePolicy idiom
1134 q->setSizePolicy(policy);
1135 textLayoutDirty = true;
1136 }
1137 q->updateGeometry();
1138 q->update(q->contentsRect());
1139}
1140
1141#ifndef QT_NO_SHORTCUT
1170{
1171 Q_D(QLabel);
1172
1173 if (d->buddy)
1174 disconnect(d->buddy, SIGNAL(destroyed()), this, SLOT(_q_buddyDeleted()));
1175
1176 d->buddy = buddy;
1177
1178 if (buddy)
1179 connect(buddy, SIGNAL(destroyed()), this, SLOT(_q_buddyDeleted()));
1180
1181 if (d->isTextLabel) {
1182 if (d->shortcutId)
1183 releaseShortcut(d->shortcutId);
1184 d->shortcutId = 0;
1185 d->textDirty = true;
1186 if (buddy)
1187 d->updateShortcut(); // grab new shortcut
1188 d->updateLabel();
1189 }
1190}
1191
1192
1200{
1201 Q_D(const QLabel);
1202 return d->buddy;
1203}
1204
1206{
1207 Q_Q(QLabel);
1208 Q_ASSERT(shortcutId == 0);
1209 // Introduce an extra boolean to indicate the presence of a shortcut in the
1210 // text. We cannot use the shortcutId itself because on the mac mnemonics are
1211 // off by default, so QKeySequence::mnemonic always returns an empty sequence.
1212 // But then we do want to hide the ampersands, so we can't use shortcutId.
1213 hasShortcut = false;
1214
1215 if (!text.contains(u'&'))
1216 return;
1217 hasShortcut = true;
1218 shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
1219}
1220
1221
1223{
1224 Q_Q(QLabel);
1225 q->setBuddy(nullptr);
1226}
1227
1228#endif // QT_NO_SHORTCUT
1229
1230#if QT_CONFIG(movie)
1231void QLabelPrivate::_q_movieUpdated(const QRect& rect)
1232{
1233 Q_Q(QLabel);
1234 if (movie && movie->isValid()) {
1235 QRect r;
1236 if (scaledcontents) {
1237 QRect cr = q->contentsRect();
1238 QRect pixmapRect(cr.topLeft(), movie->currentPixmap().size());
1239 if (pixmapRect.isEmpty())
1240 return;
1241 r.setRect(cr.left(), cr.top(),
1242 (rect.width() * cr.width()) / pixmapRect.width(),
1243 (rect.height() * cr.height()) / pixmapRect.height());
1244 } else {
1245 r = q->style()->itemPixmapRect(q->contentsRect(), align, movie->currentPixmap());
1246 r.translate(rect.x(), rect.y());
1247 r.setWidth(qMin(r.width(), rect.width()));
1248 r.setHeight(qMin(r.height(), rect.height()));
1249 }
1250 q->update(r);
1251 }
1252}
1253
1254void QLabelPrivate::_q_movieResized(const QSize& size)
1255{
1256 Q_Q(QLabel);
1257 q->update(); //we need to refresh the whole background in case the new size is smaller
1258 valid_hints = false;
1259 _q_movieUpdated(QRect(QPoint(0,0), size));
1260 q->updateGeometry();
1261}
1262
1272void QLabel::setMovie(QMovie *movie)
1273{
1274 Q_D(QLabel);
1275 d->clearContents();
1276
1277 if (!movie)
1278 return;
1279
1280 d->movie = movie;
1281 connect(movie, SIGNAL(resized(QSize)), this, SLOT(_q_movieResized(QSize)));
1282 connect(movie, SIGNAL(updated(QRect)), this, SLOT(_q_movieUpdated(QRect)));
1283
1284 // Assume that if the movie is running,
1285 // resize/update signals will come soon enough
1286 if (movie->state() != QMovie::Running)
1287 d->updateLabel();
1288}
1289
1290#endif // QT_CONFIG(movie)
1291
1299{
1300 delete control;
1301 control = nullptr;
1302 isTextLabel = false;
1303 hasShortcut = false;
1304
1305#ifndef QT_NO_PICTURE
1306 picture.reset();
1307#endif
1308 scaledpixmap.reset();
1309 cachedimage.reset();
1310 pixmap.reset();
1311
1312 text.clear();
1313 Q_Q(QLabel);
1314#ifndef QT_NO_SHORTCUT
1315 if (shortcutId)
1316 q->releaseShortcut(shortcutId);
1317 shortcutId = 0;
1318#endif
1319#if QT_CONFIG(movie)
1320 if (movie) {
1321 QObject::disconnect(movie, SIGNAL(resized(QSize)), q, SLOT(_q_movieResized(QSize)));
1322 QObject::disconnect(movie, SIGNAL(updated(QRect)), q, SLOT(_q_movieUpdated(QRect)));
1323 }
1324 movie = nullptr;
1325#endif
1326#ifndef QT_NO_CURSOR
1327 if (onAnchor) {
1328 if (validCursor)
1329 q->setCursor(cursor);
1330 else
1331 q->unsetCursor();
1332 }
1333 validCursor = false;
1334 onAnchor = false;
1335#endif
1336}
1337
1338
1339#if QT_CONFIG(movie)
1340
1348QMovie *QLabel::movie() const
1349{
1350 Q_D(const QLabel);
1351 return d->movie;
1352}
1353
1354#endif // QT_CONFIG(movie)
1355
1369{
1370 Q_D(const QLabel);
1371 return d->textformat;
1372}
1373
1375{
1376 Q_D(QLabel);
1377 if (format != d->textformat) {
1378 d->textformat = format;
1379 QString t = d->text;
1380 if (!t.isNull()) {
1381 d->text.clear();
1382 setText(t);
1383 }
1384 }
1385}
1386
1393{
1394 Q_D(const QLabel);
1395 return d->control ? d->control->document()->resourceProvider() : d->resourceProvider;
1396}
1397
1406{
1407 Q_D(QLabel);
1408 d->resourceProvider = provider;
1409 if (d->control != nullptr)
1410 d->control->document()->setResourceProvider(provider);
1411}
1412
1417{
1418 Q_D(QLabel);
1419 if (ev->type() == QEvent::FontChange || ev->type() == QEvent::ApplicationFontChange) {
1420 if (d->isTextLabel) {
1421 if (d->control)
1422 d->control->document()->setDefaultFont(font());
1423 d->updateLabel();
1424 }
1425 } else if (ev->type() == QEvent::PaletteChange && d->control) {
1426 d->control->setPalette(palette());
1427 } else if (ev->type() == QEvent::ContentsRectChange) {
1428 d->updateLabel();
1429 }
1431}
1432
1444{
1445 Q_D(const QLabel);
1446 return d->scaledcontents;
1447}
1448
1450{
1451 Q_D(QLabel);
1452 if ((bool)d->scaledcontents == enable)
1453 return;
1454 d->scaledcontents = enable;
1455 if (!enable) {
1456 d->scaledpixmap.reset();
1457 d->cachedimage.reset();
1458 }
1460}
1461
1463{
1464 if (control) {
1466 return opt.textDirection();
1467 }
1468
1470}
1471
1472
1473// Returns the rect that is available for us to draw the document
1475{
1476 Q_Q(const QLabel);
1477 Q_ASSERT_X(isTextLabel, "documentRect", "document rect called for label that is not a text label!");
1478 QRect cr = q->contentsRect();
1479 cr.adjust(margin, margin, -margin, -margin);
1481 : q->layoutDirection(), QFlag(this->align));
1482 int m = indent;
1483 if (m < 0 && q->frameWidth()) // no indent, but we do have a frame
1484 m = q->fontMetrics().horizontalAdvance(u'x') / 2 - margin;
1485 if (m > 0) {
1486 if (align & Qt::AlignLeft)
1487 cr.setLeft(cr.left() + m);
1488 if (align & Qt::AlignRight)
1489 cr.setRight(cr.right() - m);
1490 if (align & Qt::AlignTop)
1491 cr.setTop(cr.top() + m);
1492 if (align & Qt::AlignBottom)
1493 cr.setBottom(cr.bottom() - m);
1494 }
1495 return cr;
1496}
1497
1499{
1500 if (!textDirty)
1501 return;
1502 if (control) {
1503 QTextDocument *doc = control->document();
1504 if (textDirty) {
1506 doc->setPlainText(text);
1507#if QT_CONFIG(texthtmlparser)
1508 } else if (effectiveTextFormat == Qt::RichText) {
1509 doc->setHtml(text);
1510#endif
1511#if QT_CONFIG(textmarkdownreader)
1512 } else if (effectiveTextFormat == Qt::MarkdownText) {
1513 doc->setMarkdown(text);
1514#endif
1515 } else {
1516 doc->setPlainText(text);
1517 }
1518 doc->setUndoRedoEnabled(false);
1519
1520#ifndef QT_NO_SHORTCUT
1521 if (hasShortcut) {
1522 // Underline the first character that follows an ampersand (and remove the others ampersands)
1523 int from = 0;
1524 bool found = false;
1526 while (!(cursor = control->document()->find(("&"_L1), from)).isNull()) {
1527 cursor.deleteChar(); // remove the ampersand
1529 from = cursor.position();
1530 if (!found && cursor.selectedText() != "&"_L1) { //not a second &
1531 found = true;
1533 }
1534 }
1535 }
1536#endif
1537 }
1538 }
1539 textDirty = false;
1540}
1541
1543{
1544 if (!textLayoutDirty)
1545 return;
1547 if (control) {
1548 QTextDocument *doc = control->document();
1550
1551 opt.setAlignment(QFlag(this->align));
1552
1553 if (this->align & Qt::TextWordWrap)
1555 else
1556 opt.setWrapMode(QTextOption::ManualWrap);
1557
1559
1561 fmt.setMargin(0);
1562 doc->rootFrame()->setFrameFormat(fmt);
1564 }
1565 textLayoutDirty = false;
1566}
1567
1569{
1570 Q_Q(const QLabel);
1571 if (!isTextLabel)
1572 return;
1573 if (!control) {
1574 control = new QWidgetTextControl(const_cast<QLabel *>(q));
1576 control->document()->setDefaultFont(q->font());
1577 if (resourceProvider != nullptr)
1581 control->setPalette(q->palette());
1582 control->setFocus(q->hasFocus());
1583 QObject::connect(control, SIGNAL(updateRequest(QRectF)),
1584 q, SLOT(update()));
1585 QObject::connect(control, SIGNAL(linkHovered(QString)),
1587 QObject::connect(control, SIGNAL(linkActivated(QString)),
1588 q, SIGNAL(linkActivated(QString)));
1589 textLayoutDirty = true;
1590 textDirty = true;
1591 }
1592}
1593
1595{
1596 Q_Q(QLabel);
1598 e->ignore();
1599 return;
1600 }
1601 control->processEvent(e, -layoutRect().topLeft(), q);
1602}
1603
1605{
1606 Q_Q(QLabel);
1607#ifndef QT_NO_CURSOR
1608 if (anchor.isEmpty()) { // restore cursor
1609 if (validCursor)
1610 q->setCursor(cursor);
1611 else
1612 q->unsetCursor();
1613 onAnchor = false;
1614 } else if (!onAnchor) {
1615 validCursor = q->testAttribute(Qt::WA_SetCursor);
1616 if (validCursor) {
1617 cursor = q->cursor();
1618 }
1619 q->setCursor(Qt::PointingHandCursor);
1620 onAnchor = true;
1621 }
1622#endif
1623 emit q->linkHovered(anchor);
1624}
1625
1626// Return the layout rect - this is the rect that is given to the layout painting code
1627// This may be different from the document rect since vertical alignment is not
1628// done by the text layout code
1630{
1631 QRectF cr = documentRect();
1632 if (!control)
1633 return cr;
1635 // Calculate y position manually
1637 qreal yo = 0;
1638 if (align & Qt::AlignVCenter)
1639 yo = qMax((cr.height()-rh)/2, qreal(0));
1640 else if (align & Qt::AlignBottom)
1641 yo = qMax(cr.height()-rh, qreal(0));
1642 return QRectF(cr.x(), yo + cr.y(), cr.width(), cr.height());
1643}
1644
1645// Returns the point in the document rect adjusted with p
1647{
1648 QRect lr = layoutRect().toRect();
1649 return p - lr.topLeft();
1650}
1651
1652#ifndef QT_NO_CONTEXTMENU
1654{
1655 if (!control)
1656 return nullptr;
1657
1658 const QPoint p = layoutPoint(pos);
1659 return control->createStandardContextMenu(p, q_func());
1660}
1661#endif
1662
1685
1686#include "moc_qlabel.cpp"
The QAbstractButton class is the abstract base class of button widgets, providing functionality commo...
void animateClick()
Performs an animated click: the button is pressed immediately, and released 100ms later.
virtual QSizeF documentSize() const =0
Returns the total size of the document's layout.
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition qevent.h:593
const QPoint & pos() const
Returns the position of the mouse pointer relative to the widget that received the event.
Definition qevent.h:610
const QPoint & globalPos() const
Returns the global position of the mouse pointer at the time of the event.
Definition qevent.h:611
\inmodule QtCore
Definition qcoreevent.h:45
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
@ ContentsRectChange
Definition qcoreevent.h:219
@ StyleChange
Definition qcoreevent.h:136
@ FontChange
Definition qcoreevent.h:133
@ PaletteChange
Definition qcoreevent.h:94
@ MacSizeChange
Definition qcoreevent.h:217
@ ApplicationFontChange
Definition qcoreevent.h:91
Type type() const
Returns the event type.
Definition qcoreevent.h:299
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition qcoreevent.h:306
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
Definition qcoreevent.h:305
Definition qflags.h:17
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:469
Qt::FocusReason reason() const
Returns the reason for this focus event.
Definition qevent.cpp:1566
\reentrant \inmodule QtGui
QRect boundingRect(QChar) const
Returns the rectangle that is covered by ink if character ch were to be drawn at the origin of the co...
int lineSpacing() const
Returns the distance from one base line to the next.
int horizontalAdvance(const QString &, int len=-1) const
Returns the horizontal advance in pixels of the first len characters of text.
int averageCharWidth() const
short frameWidth
Definition qframe_p.h:38
The QFrame class is the base class of widgets that can have a frame.
Definition qframe.h:17
bool event(QEvent *e) override
\reimp
Definition qframe.cpp:511
void drawFrame(QPainter *)
Definition qframe.cpp:488
void changeEvent(QEvent *) override
\reimp
Definition qframe.cpp:498
@ Disabled
Definition qicon.h:22
\inmodule QtGui
Definition qimage.h:37
The QKeyEvent class describes a key event.
Definition qevent.h:423
static QKeySequence mnemonic(const QString &text)
Returns the shortcut key sequence for the mnemonic in text, or an empty key sequence if no mnemonics ...
QCursor cursor
Definition qlabel_p.h:98
std::optional< QImage > cachedimage
Definition qlabel_p.h:88
uint validCursor
Definition qlabel_p.h:118
std::optional< QPixmap > pixmap
Definition qlabel_p.h:86
std::optional< QPixmap > scaledpixmap
Definition qlabel_p.h:87
QString text
Definition qlabel_p.h:85
Qt::TextFormat effectiveTextFormat
Definition qlabel_p.h:105
QPoint layoutPoint(const QPoint &p) const
Definition qlabel.cpp:1646
QMenu * createStandardContextMenu(const QPoint &pos)
Definition qlabel.cpp:1653
uint hasShortcut
Definition qlabel_p.h:116
void sendControlEvent(QEvent *e)
Definition qlabel.cpp:1594
QRect documentRect() const
Definition qlabel.cpp:1474
void _q_buddyDeleted()
Definition qlabel.cpp:1222
QRectF layoutRect() const
Definition qlabel.cpp:1629
uint scaledcontents
Definition qlabel_p.h:112
void ensureTextControl() const
Definition qlabel.cpp:1568
Qt::LayoutDirection textDirection() const
Definition qlabel.cpp:1462
QTextCursor shortcutCursor
Definition qlabel_p.h:96
QSize sizeForWidth(int w) const
Returns the size that will be used if the width of the label is w.
Definition qlabel.cpp:554
void _q_linkHovered(const QString &link)
Definition qlabel.cpp:1604
void clearContents()
Definition qlabel.cpp:1298
uint textLayoutDirty
Definition qlabel_p.h:113
QTextDocument::ResourceProvider resourceProvider
Definition qlabel_p.h:123
void ensureTextPopulated() const
Definition qlabel.cpp:1498
uint openExternalLinks
Definition qlabel_p.h:121
QWidgetTextControl * control
Definition qlabel_p.h:95
void init()
Definition qlabel.cpp:224
uint isTextLabel
Definition qlabel_p.h:115
void updateLabel()
Updates the label, but not the frame.
Definition qlabel.cpp:1124
ushort align
Definition qlabel_p.h:109
Qt::TextInteractionFlags textInteractionFlags
Definition qlabel_p.h:106
uint valid_hints
Definition qlabel_p.h:111
void updateShortcut()
Definition qlabel.cpp:1205
void ensureTextLayouted() const
Definition qlabel.cpp:1542
The QLabel widget provides a text or image display.
Definition qlabel.h:20
int indent
the label's text indent in pixels
Definition qlabel.h:29
void setBuddy(QWidget *)
Sets this label's buddy to buddy.
Definition qlabel.cpp:1169
~QLabel()
Destroys the label.
Definition qlabel.cpp:218
void changeEvent(QEvent *) override
\reimp
Definition qlabel.cpp:1416
QString selectedText
the selected text
Definition qlabel.h:34
QLabel(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
Constructs an empty label.
Definition qlabel.cpp:191
Qt::TextFormat textFormat
the label's text format
Definition qlabel.h:23
bool focusNextPrevChild(bool next) override
\reimp
Definition qlabel.cpp:938
int heightForWidth(int) const override
\reimp
Definition qlabel.cpp:650
void setText(const QString &)
Definition qlabel.cpp:263
QPicture picture() const
Definition qlabel.cpp:173
void setOpenExternalLinks(bool open)
Definition qlabel.cpp:679
QSize minimumSizeHint() const override
\reimp
Definition qlabel.cpp:831
Qt::TextInteractionFlags textInteractionFlags
Definition qlabel.h:32
QWidget * buddy() const
Returns this label's buddy, or nullptr if no buddy is currently set.
Definition qlabel.cpp:1199
void setResourceProvider(const QTextDocument::ResourceProvider &provider)
Definition qlabel.cpp:1405
bool hasSelectedText
whether there is any text selected
Definition qlabel.h:33
QTextDocument::ResourceProvider resourceProvider() const
Definition qlabel.cpp:1392
void keyPressEvent(QKeyEvent *ev) override
\reimp
Definition qlabel.cpp:948
void clear()
Clears any label contents.
Definition qlabel.cpp:325
void setTextFormat(Qt::TextFormat)
Definition qlabel.cpp:1374
void focusOutEvent(QFocusEvent *ev) override
\reimp
Definition qlabel.cpp:918
void setMargin(int)
Definition qlabel.cpp:541
void contextMenuEvent(QContextMenuEvent *ev) override
\reimp
Definition qlabel.cpp:884
void paintEvent(QPaintEvent *) override
\reimp
Definition qlabel.cpp:1001
QPixmap pixmap
the label's pixmap.
Definition qlabel.h:24
void setIndent(int)
Definition qlabel.cpp:510
void setPixmap(const QPixmap &)
Definition qlabel.cpp:339
void focusInEvent(QFocusEvent *ev) override
\reimp
Definition qlabel.cpp:905
bool hasScaledContents() const
Definition qlabel.cpp:1443
void setAlignment(Qt::Alignment)
Definition qlabel.cpp:442
void setPicture(const QPicture &)
Sets the label contents to picture.
Definition qlabel.cpp:385
int selectionStart() const
selectionStart() returns the index of the first selected character in the label or -1 if no text is s...
Definition qlabel.cpp:810
void setSelection(int, int)
Selects text from position start and for length characters.
Definition qlabel.cpp:739
int margin
the width of the margin
Definition qlabel.h:28
Qt::Alignment alignment
the alignment of the label's contents
Definition qlabel.h:26
void setWordWrap(bool on)
Definition qlabel.cpp:472
void mouseReleaseEvent(QMouseEvent *ev) override
\reimp
Definition qlabel.cpp:875
bool wordWrap
the label's word-wrapping policy
Definition qlabel.h:27
void mousePressEvent(QMouseEvent *ev) override
\reimp
Definition qlabel.cpp:859
QString text
the label's text
Definition qlabel.h:22
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
Definition qlabel.cpp:699
void mouseMoveEvent(QMouseEvent *ev) override
\reimp
Definition qlabel.cpp:867
bool event(QEvent *e) override
\reimp
Definition qlabel.cpp:956
bool openExternalLinks
Definition qlabel.h:30
void setNum(int)
Sets the label contents to plain text containing the textual representation of integer num.
Definition qlabel.cpp:406
QSize sizeHint() const override
\reimp
Definition qlabel.cpp:820
void setScaledContents(bool)
Definition qlabel.cpp:1449
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
void popup(const QPoint &pos, QAction *at=nullptr)
Displays the menu so that the action atAction will be at the specified global position p.
Definition qmenu.cpp:2288
\inmodule QtGui
Definition qevent.h:195
\inmodule QtGui
Definition qmovie.h:28
MovieState state() const
Returns the current state of QMovie.
Definition qmovie.cpp:717
@ Running
Definition qmovie.h:37
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3099
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
qreal devicePixelRatio() const
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:485
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation.
void restore()
Restores the current painter state (pops a saved state off the stack).
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
void save()
Saves the current painter state (pushes the state onto a stack).
void drawPicture(const QPointF &p, const QPicture &picture)
Replays the given picture at the given point.
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
The QPicture class is a paint device that records and replays QPainter commands.
Definition qpicture.h:19
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition qpixmap.cpp:1445
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
Definition qpixmap.cpp:888
\inmodule QtCore\reentrant
Definition qpoint.h:23
\inmodule QtCore\reentrant
Definition qrect.h:483
constexpr qreal y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:658
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:718
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:715
constexpr qreal x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:655
constexpr QRectF translated(qreal dx, qreal dy) const noexcept
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis,...
Definition qrect.h:748
constexpr QPointF topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:510
constexpr QRect toRect() const noexcept
Returns a QRect based on the values of this rectangle.
Definition qrect.h:845
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr void adjust(int x1, int y1, int x2, int y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition qrect.h:372
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:238
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:181
constexpr void setRight(int pos) noexcept
Sets the right edge of the rectangle to the given x coordinate.
Definition qrect.h:196
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:220
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
Definition qrect.h:386
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:175
constexpr void setBottom(int pos) noexcept
Sets the bottom edge of the rectangle to the given y coordinate.
Definition qrect.h:199
constexpr void setLeft(int pos) noexcept
Sets the left edge of the rectangle to the given x coordinate.
Definition qrect.h:190
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:172
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:184
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:241
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:235
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:187
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:178
constexpr void setTop(int pos) noexcept
Sets the top edge of the rectangle to the given y coordinate.
Definition qrect.h:193
The QShortcutEvent class provides an event which is generated when the user presses a key combination...
\inmodule QtCore
Definition qsize.h:207
constexpr qreal width() const noexcept
Returns the width.
Definition qsize.h:321
constexpr qreal height() const noexcept
Returns the height.
Definition qsize.h:324
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
constexpr void setHeightForWidth(bool b) noexcept
Sets the flag determining whether the widget's preferred height depends on its width,...
Definition qsizepolicy.h:80
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:132
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:129
constexpr int & rheight() noexcept
Returns a reference to the height.
Definition qsize.h:156
constexpr int & rwidth() noexcept
Returns a reference to the width.
Definition qsize.h:153
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1107
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:1083
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.h:1217
bool isRightToLeft() const
Returns true if the string is read right to left.
Definition qstring.cpp:9068
QString & setNum(short, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.h:1112
The QStyleOption class stores the parameters used by QStyle functions.
QPalette palette
void initFrom(const QWidget *w)
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLe...
Definition qstyle.cpp:2203
@ SH_UnderlineShortcut
Definition qstyle.h:624
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const =0
Returns an integer representing the specified style hint for the given widget described by the provid...
virtual void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
Draws the given pixmap in the specified rectangle, according to the specified alignment,...
Definition qstyle.cpp:612
virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const =0
Returns a copy of the given pixmap, styled to conform to the specified iconMode and taking into accou...
virtual void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const
Draws the given text in the specified rectangle using the provided painter and palette.
Definition qstyle.cpp:574
@ SE_LabelLayoutItem
Definition qstyle.h:292
\reentrant \inmodule QtGui
Definition qtextcursor.h:30
\reentrant \inmodule QtGui
void setHtml(const QString &html)
Replaces the entire contents of the document with the given HTML-formatted text in the html string.
void setDefaultTextOption(const QTextOption &option)
void setResourceProvider(const ResourceProvider &provider)
QAbstractTextDocumentLayout * documentLayout() const
Returns the document layout for this document.
QTextOption defaultTextOption() const
the default text option will be set on all \l{QTextLayout}s in the document.
void setDefaultFont(const QFont &font)
Sets the default font to use in the document layout.
void setUndoRedoEnabled(bool enable)
QTextCursor find(const QString &subString, int from=0, FindFlags options=FindFlags()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setPlainText(const QString &text)
Replaces the entire contents of the document with the given plain text.
QTextFrame * rootFrame() const
Returns the document's root frame.
std::function< QVariant(const QUrl &)> ResourceProvider
void setTextWidth(qreal width)
void setFrameFormat(const QTextFrameFormat &format)
Sets the frame's format.
QTextFrameFormat frameFormat() const
Returns the frame's format.
Definition qtextobject.h:89
\reentrant
Definition qtextoption.h:18
void setWrapMode(WrapMode wrap)
Sets the option's text wrap mode to the given mode.
Definition qtextoption.h:67
void setLayoutItemMargins(int left, int top, int right, int bottom)
short bottommargin
Definition qwidget_p.h:688
short rightmargin
Definition qwidget_p.h:687
void update(T t)
void setOpenExternalLinks(bool open)
void setFocus(bool focus, Qt::FocusReason=Qt::OtherFocusReason)
virtual void processEvent(QEvent *e, const QTransform &transform, QWidget *contextWidget=nullptr)
QMenu * createStandardContextMenu(const QPointF &pos, QWidget *parent)
void setPalette(const QPalette &pal)
QTextDocument * document() const
void setTextWidth(qreal width)
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
QWidget * window() const
Returns the window for this widget, i.e.
Definition qwidget.cpp:4320
void releaseShortcut(int id)
Removes the shortcut with the given id from Qt's shortcut system.
Qt::LayoutDirection layoutDirection
the layout direction for this widget.
Definition qwidget.h:170
QPalette palette
the widget's palette
Definition qwidget.h:132
void setMouseTracking(bool enable)
Definition qwidget.h:853
QRect contentsRect() const
Returns the area inside the widget's margins.
Definition qwidget.cpp:7753
virtual void focusInEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition qwidget.cpp:9711
QSizePolicy sizePolicy
the default layout behavior of the widget
Definition qwidget.h:119
void setFocusPolicy(Qt::FocusPolicy policy)
Definition qwidget.cpp:7904
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab,...
Definition qwidget.cpp:6800
void ensurePolished() const
Ensures that the widget and its children have been polished by QStyle (i.e., have a proper font and p...
bool isEnabled() const
Definition qwidget.h:814
void update()
Updates the widget unless updates are disabled or the widget is hidden.
friend class QPixmap
Definition qwidget.h:748
QStyle * style() const
Definition qwidget.cpp:2607
QFont font
the font currently set for the widget
Definition qwidget.h:133
virtual void focusOutEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition qwidget.cpp:9737
QPalette::ColorRole foregroundRole() const
Returns the foreground role.
Definition qwidget.cpp:4418
QCursor cursor
the cursor shape for this widget
Definition qwidget.h:135
virtual int heightForWidth(int) const
Returns the preferred height for this widget, given the width w.
QString str
[2]
QString text
QPushButton * button
[2]
QCursor cursor
double e
rect
[4]
QPixmap pix
uint alignment
QStyleOptionButton opt
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
@ AlignRight
Definition qnamespace.h:145
@ AlignBottom
Definition qnamespace.h:153
@ AlignVCenter
Definition qnamespace.h:154
@ AlignTop
Definition qnamespace.h:152
@ AlignHCenter
Definition qnamespace.h:147
@ AlignHorizontal_Mask
Definition qnamespace.h:150
@ AlignVertical_Mask
Definition qnamespace.h:160
@ AlignLeft
Definition qnamespace.h:143
@ TextSelectableByMouse
@ LinksAccessibleByKeyboard
@ TextSelectableByKeyboard
@ NoTextInteraction
@ SmoothTransformation
@ WA_SetCursor
Definition qnamespace.h:304
@ WA_KeyboardFocusChange
Definition qnamespace.h:343
@ WA_DeleteOnClose
Definition qnamespace.h:320
TextFormat
@ RichText
@ MarkdownText
@ PlainText
@ AutoText
LayoutDirection
@ LeftToRight
@ RightToLeft
@ IgnoreAspectRatio
@ ClickFocus
Definition qnamespace.h:108
@ NoFocus
Definition qnamespace.h:106
@ StrongFocus
Definition qnamespace.h:109
@ TextWordWrap
Definition qnamespace.h:173
@ TextHideMnemonic
Definition qnamespace.h:177
@ TextForceRightToLeft
Definition qnamespace.h:180
@ TextShowMnemonic
Definition qnamespace.h:172
@ TextForceLeftToRight
Definition qnamespace.h:179
@ PointingHandCursor
Q_GUI_EXPORT bool mightBeRichText(const QString &)
Returns true if the string text is likely to be rich text; otherwise returns false.
FocusReason
@ PopupFocusReason
@ ActiveWindowFocusReason
@ ShortcutFocusReason
static void * context
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
int qCeil(T v)
Definition qmath.h:36
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
#define SLOT(a)
Definition qobjectdefs.h:51
#define SIGNAL(a)
Definition qobjectdefs.h:52
const GLfloat * m
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLenum GLuint GLenum GLsizei length
GLfloat GLfloat f
GLint GLsizei width
GLenum type
GLbitfield flags
GLboolean enable
GLuint start
GLint GLsizei GLsizei GLenum format
struct _cl_event * event
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
GLuint num
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
static QT_BEGIN_NAMESPACE QAsn1Element wrap(quint8 type, const QAsn1Element &child)
QStyleSheetStyle * qt_styleSheet(QStyle *style)
#define QT_CONFIG(feature)
#define emit
double qreal
Definition qtypes.h:92
QVideoFrameFormat::PixelFormat fmt
#define QWIDGETSIZE_MAX
Definition qwidget.h:930
if(qFloatDistance(a, b)<(1<< 7))
[0]
file open(QIODevice::ReadOnly)
QObject::connect nullptr
myObject disconnect()
[26]
widget render & pixmap
QPainter painter(this)
[7]
QMenu menu
[5]
QSizePolicy policy
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent