Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
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
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();
1050 painter.translate(lr.topLeft());
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)
1176
1177 d->buddy = buddy;
1178
1179 if (buddy)
1182
1183 if (d->isTextLabel) {
1184 if (d->shortcutId)
1185 releaseShortcut(d->shortcutId);
1186 d->shortcutId = 0;
1187 d->textDirty = true;
1188 if (buddy)
1189 d->updateShortcut(); // grab new shortcut
1190 d->updateLabel();
1191 }
1192}
1193
1194
1202{
1203 Q_D(const QLabel);
1204 return d->buddy;
1205}
1206
1208{
1209 Q_Q(QLabel);
1210 Q_ASSERT(shortcutId == 0);
1211 // Introduce an extra boolean to indicate the presence of a shortcut in the
1212 // text. We cannot use the shortcutId itself because on the mac mnemonics are
1213 // off by default, so QKeySequence::mnemonic always returns an empty sequence.
1214 // But then we do want to hide the ampersands, so we can't use shortcutId.
1215 hasShortcut = false;
1216
1217 if (!text.contains(u'&'))
1218 return;
1219 hasShortcut = true;
1220 shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
1221}
1222
1223
1225{
1226 Q_Q(QLabel);
1227 q->setBuddy(nullptr);
1228}
1229
1230#endif // QT_NO_SHORTCUT
1231
1232#if QT_CONFIG(movie)
1233void QLabelPrivate::movieUpdated(const QRect &rect)
1234{
1235 Q_Q(QLabel);
1236 if (movie && movie->isValid()) {
1237 QRect r;
1238 if (scaledcontents) {
1239 QRect cr = q->contentsRect();
1240 QRect pixmapRect(cr.topLeft(), movie->currentPixmap().size());
1241 if (pixmapRect.isEmpty())
1242 return;
1243 r.setRect(cr.left(), cr.top(),
1244 (rect.width() * cr.width()) / pixmapRect.width(),
1245 (rect.height() * cr.height()) / pixmapRect.height());
1246 } else {
1247 r = q->style()->itemPixmapRect(q->contentsRect(), align, movie->currentPixmap());
1248 r.translate(rect.x(), rect.y());
1249 r.setWidth(qMin(r.width(), rect.width()));
1250 r.setHeight(qMin(r.height(), rect.height()));
1251 }
1252 q->update(r);
1253 }
1254}
1255
1256void QLabelPrivate::movieResized(const QSize &size)
1257{
1258 Q_Q(QLabel);
1259 q->update(); //we need to refresh the whole background in case the new size is smaller
1260 valid_hints = false;
1261 movieUpdated(QRect(QPoint(0,0), size));
1262 q->updateGeometry();
1263}
1264
1274void QLabel::setMovie(QMovie *movie)
1275{
1276 Q_D(QLabel);
1277 d->clearContents();
1278
1279 if (!movie)
1280 return;
1281
1282 d->movie = movie;
1283 d->movieConnections = {
1284 QObjectPrivate::connect(movie, &QMovie::resized, d, &QLabelPrivate::movieResized),
1285 QObjectPrivate::connect(movie, &QMovie::updated, d, &QLabelPrivate::movieUpdated),
1286 };
1287
1288 // Assume that if the movie is running,
1289 // resize/update signals will come soon enough
1290 if (movie->state() != QMovie::Running)
1291 d->updateLabel();
1292}
1293
1294#endif // QT_CONFIG(movie)
1295
1303{
1304 delete control;
1305 control = nullptr;
1306 isTextLabel = false;
1307 hasShortcut = false;
1308
1309#ifndef QT_NO_PICTURE
1310 picture.reset();
1311#endif
1312 scaledpixmap.reset();
1313 cachedimage.reset();
1314 pixmap.reset();
1315
1316 text.clear();
1317 Q_Q(QLabel);
1318#ifndef QT_NO_SHORTCUT
1319 if (shortcutId)
1320 q->releaseShortcut(shortcutId);
1321 shortcutId = 0;
1322#endif
1323#if QT_CONFIG(movie)
1324 for (const auto &conn : std::as_const(movieConnections))
1325 QObject::disconnect(conn);
1326 movie = nullptr;
1327#endif
1328#ifndef QT_NO_CURSOR
1329 if (onAnchor) {
1330 if (validCursor)
1331 q->setCursor(cursor);
1332 else
1333 q->unsetCursor();
1334 }
1335 validCursor = false;
1336 onAnchor = false;
1337#endif
1338}
1339
1340
1341#if QT_CONFIG(movie)
1342
1350QMovie *QLabel::movie() const
1351{
1352 Q_D(const QLabel);
1353 return d->movie;
1354}
1355
1356#endif // QT_CONFIG(movie)
1357
1371{
1372 Q_D(const QLabel);
1373 return d->textformat;
1374}
1375
1377{
1378 Q_D(QLabel);
1379 if (format != d->textformat) {
1380 d->textformat = format;
1381 QString t = d->text;
1382 if (!t.isNull()) {
1383 d->text.clear();
1384 setText(t);
1385 }
1386 }
1387}
1388
1395{
1396 Q_D(const QLabel);
1397 return d->control ? d->control->document()->resourceProvider() : d->resourceProvider;
1398}
1399
1408{
1409 Q_D(QLabel);
1410 d->resourceProvider = provider;
1411 if (d->control != nullptr)
1412 d->control->document()->setResourceProvider(provider);
1413}
1414
1419{
1420 Q_D(QLabel);
1421 if (ev->type() == QEvent::FontChange || ev->type() == QEvent::ApplicationFontChange) {
1422 if (d->isTextLabel) {
1423 if (d->control)
1424 d->control->document()->setDefaultFont(font());
1425 d->updateLabel();
1426 }
1427 } else if (ev->type() == QEvent::PaletteChange && d->control) {
1428 d->control->setPalette(palette());
1429 } else if (ev->type() == QEvent::ContentsRectChange) {
1430 d->updateLabel();
1431 }
1433}
1434
1446{
1447 Q_D(const QLabel);
1448 return d->scaledcontents;
1449}
1450
1452{
1453 Q_D(QLabel);
1454 if ((bool)d->scaledcontents == enable)
1455 return;
1456 d->scaledcontents = enable;
1457 if (!enable) {
1458 d->scaledpixmap.reset();
1459 d->cachedimage.reset();
1460 }
1462}
1463
1465{
1466 if (control) {
1468 return opt.textDirection();
1469 }
1470
1472}
1473
1474
1475// Returns the rect that is available for us to draw the document
1477{
1478 Q_Q(const QLabel);
1479 Q_ASSERT_X(isTextLabel, "documentRect", "document rect called for label that is not a text label!");
1480 QRect cr = q->contentsRect();
1481 cr.adjust(margin, margin, -margin, -margin);
1483 : q->layoutDirection(), QFlag(this->align));
1484 int m = indent;
1485 if (m < 0 && q->frameWidth()) // no indent, but we do have a frame
1486 m = q->fontMetrics().horizontalAdvance(u'x') / 2 - margin;
1487 if (m > 0) {
1488 if (align & Qt::AlignLeft)
1489 cr.setLeft(cr.left() + m);
1490 if (align & Qt::AlignRight)
1491 cr.setRight(cr.right() - m);
1492 if (align & Qt::AlignTop)
1493 cr.setTop(cr.top() + m);
1494 if (align & Qt::AlignBottom)
1495 cr.setBottom(cr.bottom() - m);
1496 }
1497 return cr;
1498}
1499
1501{
1502 if (!textDirty)
1503 return;
1504 if (control) {
1505 QTextDocument *doc = control->document();
1506 if (textDirty) {
1508 doc->setPlainText(text);
1509#if QT_CONFIG(texthtmlparser)
1510 } else if (effectiveTextFormat == Qt::RichText) {
1511 doc->setHtml(text);
1512#endif
1513#if QT_CONFIG(textmarkdownreader)
1514 } else if (effectiveTextFormat == Qt::MarkdownText) {
1515 doc->setMarkdown(text);
1516#endif
1517 } else {
1518 doc->setPlainText(text);
1519 }
1520 doc->setUndoRedoEnabled(false);
1521
1522#ifndef QT_NO_SHORTCUT
1523 if (hasShortcut) {
1524 // Underline the first character that follows an ampersand (and remove the others ampersands)
1525 int from = 0;
1526 bool found = false;
1528 while (!(cursor = control->document()->find(("&"_L1), from)).isNull()) {
1529 cursor.deleteChar(); // remove the ampersand
1531 from = cursor.position();
1532 if (!found && cursor.selectedText() != "&"_L1) { //not a second &
1533 found = true;
1535 }
1536 }
1537 }
1538#endif
1539 }
1540 }
1541 textDirty = false;
1542}
1543
1545{
1546 if (!textLayoutDirty)
1547 return;
1549 if (control) {
1550 QTextDocument *doc = control->document();
1552
1553 opt.setAlignment(QFlag(this->align));
1554
1555 if (this->align & Qt::TextWordWrap)
1557 else
1558 opt.setWrapMode(QTextOption::ManualWrap);
1559
1561
1563 fmt.setMargin(0);
1564 doc->rootFrame()->setFrameFormat(fmt);
1566 }
1567 textLayoutDirty = false;
1568}
1569
1595
1597{
1598 Q_Q(QLabel);
1600 e->ignore();
1601 return;
1602 }
1603 control->processEvent(e, -layoutRect().topLeft(), q);
1604}
1605
1607{
1608 Q_Q(QLabel);
1609#ifndef QT_NO_CURSOR
1610 if (anchor.isEmpty()) { // restore cursor
1611 if (validCursor)
1612 q->setCursor(cursor);
1613 else
1614 q->unsetCursor();
1615 onAnchor = false;
1616 } else if (!onAnchor) {
1617 validCursor = q->testAttribute(Qt::WA_SetCursor);
1618 if (validCursor) {
1619 cursor = q->cursor();
1620 }
1621 q->setCursor(Qt::PointingHandCursor);
1622 onAnchor = true;
1623 }
1624#endif
1625 emit q->linkHovered(anchor);
1626}
1627
1628// Return the layout rect - this is the rect that is given to the layout painting code
1629// This may be different from the document rect since vertical alignment is not
1630// done by the text layout code
1632{
1633 QRectF cr = documentRect();
1634 if (!control)
1635 return cr;
1637 // Calculate y position manually
1638 qreal rh = control->document()->documentLayout()->documentSize().height();
1639 qreal yo = 0;
1640 if (align & Qt::AlignVCenter)
1641 yo = qMax((cr.height()-rh)/2, qreal(0));
1642 else if (align & Qt::AlignBottom)
1643 yo = qMax(cr.height()-rh, qreal(0));
1644 return QRectF(cr.x(), yo + cr.y(), cr.width(), cr.height());
1645}
1646
1647// Returns the point in the document rect adjusted with p
1649{
1650 QRect lr = layoutRect().toRect();
1651 return p - lr.topLeft();
1652}
1653
1654#ifndef QT_NO_CONTEXTMENU
1656{
1657 if (!control)
1658 return nullptr;
1659
1660 const QPoint p = layoutPoint(pos);
1661 return control->createStandardContextMenu(p, q_func());
1662}
1663#endif
1664
1687
1688#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:594
\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:304
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition qcoreevent.h:311
Definition qflags.h:17
The QFocusEvent class contains event parameters for widget focus events.
Definition qevent.h:470
\reentrant \inmodule QtGui
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
QImage scaled(int w, int h, Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode mode=Qt::FastTransformation) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qimage.h:209
The QKeyEvent class describes a key event.
Definition qevent.h:424
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:102
std::optional< QImage > cachedimage
Definition qlabel_p.h:91
uint validCursor
Definition qlabel_p.h:122
std::optional< QPixmap > pixmap
Definition qlabel_p.h:89
std::optional< QPixmap > scaledpixmap
Definition qlabel_p.h:90
QString text
Definition qlabel_p.h:88
Qt::TextFormat effectiveTextFormat
Definition qlabel_p.h:109
QPoint layoutPoint(const QPoint &p) const
Definition qlabel.cpp:1648
QMenu * createStandardContextMenu(const QPoint &pos)
Definition qlabel.cpp:1655
uint hasShortcut
Definition qlabel_p.h:120
void linkHovered(const QString &link)
Definition qlabel.cpp:1606
void sendControlEvent(QEvent *e)
Definition qlabel.cpp:1596
QRect documentRect() const
Definition qlabel.cpp:1476
QRectF layoutRect() const
Definition qlabel.cpp:1631
uint scaledcontents
Definition qlabel_p.h:116
void ensureTextControl() const
Definition qlabel.cpp:1570
Qt::LayoutDirection textDirection() const
Definition qlabel.cpp:1464
QTextCursor shortcutCursor
Definition qlabel_p.h:100
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 buddyDeleted()
Definition qlabel.cpp:1224
void clearContents()
Definition qlabel.cpp:1302
uint textLayoutDirty
Definition qlabel_p.h:117
QTextDocument::ResourceProvider resourceProvider
Definition qlabel_p.h:127
void ensureTextPopulated() const
Definition qlabel.cpp:1500
uint openExternalLinks
Definition qlabel_p.h:125
QWidgetTextControl * control
Definition qlabel_p.h:99
void init()
Definition qlabel.cpp:224
uint isTextLabel
Definition qlabel_p.h:119
void updateLabel()
Updates the label, but not the frame.
Definition qlabel.cpp:1124
ushort align
Definition qlabel_p.h:113
Qt::TextInteractionFlags textInteractionFlags
Definition qlabel_p.h:110
uint valid_hints
Definition qlabel_p.h:115
void updateShortcut()
Definition qlabel.cpp:1207
void ensureTextLayouted() const
Definition qlabel.cpp:1544
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:1418
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:1201
void setResourceProvider(const QTextDocument::ResourceProvider &provider)
Definition qlabel.cpp:1407
bool hasSelectedText
whether there is any text selected
Definition qlabel.h:33
QTextDocument::ResourceProvider resourceProvider() const
Definition qlabel.cpp:1394
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:1376
void linkActivated(const QString &link)
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:1445
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:1451
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:2310
\inmodule QtGui
Definition qevent.h:196
\inmodule QtGui
Definition qmovie.h:28
void updated(const QRect &rect)
This signal is emitted when the rect rect in the current frame has been updated.
MovieState state() const
Returns the current state of QMovie.
Definition qmovie.cpp:736
@ Running
Definition qmovie.h:37
void resized(const QSize &size)
This signal is emitted when the current frame has been resized to size.
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
Definition qobject_p.h:299
static bool disconnect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot)
Definition qobject_p.h:328
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3236
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:486
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.
const QBrush & text() const
Returns the text foreground brush of the current color group.
Definition qpalette.h:88
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:1437
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
Definition qpixmap.cpp:884
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:484
QRect toAlignedRect() const noexcept
Definition qrect.cpp:2338
constexpr qreal y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:672
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:729
constexpr qreal x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:669
constexpr QRect toRect() const noexcept
Returns a QRect based on the values of this rectangle.
Definition qrect.h:859
\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:373
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:182
constexpr void setRight(int pos) noexcept
Sets the right edge of the rectangle to the given x coordinate.
Definition qrect.h:197
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
constexpr void setSize(const QSize &s) noexcept
Sets the size of the rectangle to the given size.
Definition qrect.h:387
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:176
constexpr void setBottom(int pos) noexcept
Sets the bottom edge of the rectangle to the given y coordinate.
Definition qrect.h:200
constexpr void setLeft(int pos) noexcept
Sets the left edge of the rectangle to the given x coordinate.
Definition qrect.h:191
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:173
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:185
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:188
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:179
constexpr void setTop(int pos) noexcept
Sets the top edge of the rectangle to the given y coordinate.
Definition qrect.h:194
The QShortcutEvent class provides an event which is generated when the user presses a key combination...
\inmodule QtCore
Definition qsize.h:208
constexpr qreal width() const noexcept
Returns the width.
Definition qsize.h:332
constexpr qreal height() const noexcept
Returns the height.
Definition qsize.h:335
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:133
constexpr int & rheight() noexcept
Returns a reference to the height.
Definition qsize.h:157
constexpr int & rwidth() noexcept
Returns a reference to the width.
Definition qsize.h:154
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1252
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.h:1369
bool isRightToLeft() const
Returns true if the string is read right to left.
Definition qstring.cpp:9307
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:1257
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:2202
@ SH_UnderlineShortcut
Definition qstyle.h:626
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
void setFontUnderline(bool underline)
If underline is true, sets the text format's font to be underlined; otherwise it is displayed non-und...
\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 setMargin(qreal margin)
Sets the frame's margin in pixels.
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:696
short rightmargin
Definition qwidget_p.h:695
void setOpenExternalLinks(bool open)
void linkActivated(const QString &link)
void setFocus(bool focus, Qt::FocusReason=Qt::OtherFocusReason)
void updateRequest(const QRectF &rect=QRectF())
virtual void processEvent(QEvent *e, const QTransform &transform, QWidget *contextWidget=nullptr)
QMenu * createStandardContextMenu(const QPointF &pos, QWidget *parent)
void linkHovered(const QString &)
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:4313
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:7667
virtual void focusInEvent(QFocusEvent *event)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition qwidget.cpp:9665
QSizePolicy sizePolicy
the default layout behavior of the widget
Definition qwidget.h:119
void setFocusPolicy(Qt::FocusPolicy policy)
Definition qwidget.cpp:7822
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:6777
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:2600
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:9691
QPalette::ColorRole foregroundRole() const
Returns the foreground role.
Definition qwidget.cpp:4411
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
rect
[4]
QPixmap pix
uint alignment
QStyleOptionButton opt
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
Definition qcompare.h:63
@ AlignRight
Definition qnamespace.h:146
@ AlignBottom
Definition qnamespace.h:154
@ AlignVCenter
Definition qnamespace.h:155
@ AlignTop
Definition qnamespace.h:153
@ AlignHCenter
Definition qnamespace.h:148
@ AlignHorizontal_Mask
Definition qnamespace.h:151
@ AlignVertical_Mask
Definition qnamespace.h:161
@ AlignLeft
Definition qnamespace.h:144
@ TextSelectableByMouse
@ LinksAccessibleByKeyboard
@ TextSelectableByKeyboard
@ NoTextInteraction
@ SmoothTransformation
@ WA_SetCursor
Definition qnamespace.h:305
@ WA_KeyboardFocusChange
Definition qnamespace.h:344
@ WA_DeleteOnClose
Definition qnamespace.h:321
TextFormat
@ RichText
@ MarkdownText
@ PlainText
@ AutoText
LayoutDirection
@ LeftToRight
@ RightToLeft
@ IgnoreAspectRatio
@ ClickFocus
Definition qnamespace.h:109
@ NoFocus
Definition qnamespace.h:107
@ StrongFocus
Definition qnamespace.h:110
@ TextWordWrap
Definition qnamespace.h:174
@ TextHideMnemonic
Definition qnamespace.h:178
@ TextForceRightToLeft
Definition qnamespace.h:181
@ TextShowMnemonic
Definition qnamespace.h:173
@ TextForceLeftToRight
Definition qnamespace.h:180
Q_GUI_EXPORT bool mightBeRichText(QAnyStringView)
Returns true if the string text is likely to be rich text; otherwise returns false.
@ PointingHandCursor
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
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:187
QVideoFrameFormat::PixelFormat fmt
#define QWIDGETSIZE_MAX
Definition qwidget.h:917
if(qFloatDistance(a, b)<(1<< 7))
[0]
file open(QIODevice::ReadOnly)
QObject::connect nullptr
widget render & pixmap
QPainter painter(this)
[7]
QMenu menu
[5]
QSizePolicy policy