Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qlabel.h
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#ifndef QLABEL_H
5#define QLABEL_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qframe.h>
9#include <QtGui/qpicture.h>
10#include <QtGui/qtextdocument.h>
11
13
14QT_BEGIN_NAMESPACE
15
16
17class QLabelPrivate;
18
19class Q_WIDGETS_EXPORT QLabel : public QFrame
20{
21 Q_OBJECT
22 Q_PROPERTY(QString text READ text WRITE setText)
23 Q_PROPERTY(Qt::TextFormat textFormat READ textFormat WRITE setTextFormat)
24 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
25 Q_PROPERTY(bool scaledContents READ hasScaledContents WRITE setScaledContents)
26 Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
27 Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
28 Q_PROPERTY(int margin READ margin WRITE setMargin)
29 Q_PROPERTY(int indent READ indent WRITE setIndent)
30 Q_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks)
31 Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags
32 WRITE setTextInteractionFlags)
33 Q_PROPERTY(bool hasSelectedText READ hasSelectedText)
34 Q_PROPERTY(QString selectedText READ selectedText)
35
36public:
37 explicit QLabel(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags());
38 explicit QLabel(const QString &text, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags());
39 ~QLabel();
40
41 QString text() const;
42
43#if QT_DEPRECATED_SINCE(6,6)
44 QPixmap pixmap(Qt::ReturnByValueConstant) const { return pixmap(); }
45#endif
46 QPixmap pixmap() const;
47
48#ifndef QT_NO_PICTURE
49#if QT_DEPRECATED_SINCE(6,6)
50 QPicture picture(Qt::ReturnByValueConstant) const { return picture(); }
51#endif
52 QPicture picture() const;
53#endif
54#if QT_CONFIG(movie)
55 QMovie *movie() const;
56#endif
57
58 Qt::TextFormat textFormat() const;
59 void setTextFormat(Qt::TextFormat);
60
61 QTextDocument::ResourceProvider resourceProvider() const;
62 void setResourceProvider(const QTextDocument::ResourceProvider &provider);
63
64 Qt::Alignment alignment() const;
65 void setAlignment(Qt::Alignment);
66
67 void setWordWrap(bool on);
68 bool wordWrap() const;
69
70 int indent() const;
71 void setIndent(int);
72
73 int margin() const;
74 void setMargin(int);
75
76 bool hasScaledContents() const;
77 void setScaledContents(bool);
78 QSize sizeHint() const override;
79 QSize minimumSizeHint() const override;
80#ifndef QT_NO_SHORTCUT
81 void setBuddy(QWidget *);
82 QWidget *buddy() const;
83#endif
84 int heightForWidth(int) const override;
85
86 bool openExternalLinks() const;
87 void setOpenExternalLinks(bool open);
88
89 void setTextInteractionFlags(Qt::TextInteractionFlags flags);
90 Qt::TextInteractionFlags textInteractionFlags() const;
91
92 void setSelection(int, int);
93 bool hasSelectedText() const;
94 QString selectedText() const;
95 int selectionStart() const;
96
97public Q_SLOTS:
98 void setText(const QString &);
99 void setPixmap(const QPixmap &);
100#ifndef QT_NO_PICTURE
101 void setPicture(const QPicture &);
102#endif
103#if QT_CONFIG(movie)
104 void setMovie(QMovie *movie);
105#endif
106 void setNum(int);
107 void setNum(double);
108 void clear();
109
110Q_SIGNALS:
111 void linkActivated(const QString& link);
112 void linkHovered(const QString& link);
113
114protected:
115 bool event(QEvent *e) override;
116 void keyPressEvent(QKeyEvent *ev) override;
117 void paintEvent(QPaintEvent *) override;
118 void changeEvent(QEvent *) override;
119 void mousePressEvent(QMouseEvent *ev) override;
120 void mouseMoveEvent(QMouseEvent *ev) override;
121 void mouseReleaseEvent(QMouseEvent *ev) override;
122#ifndef QT_NO_CONTEXTMENU
123 void contextMenuEvent(QContextMenuEvent *ev) override;
124#endif // QT_NO_CONTEXTMENU
125 void focusInEvent(QFocusEvent *ev) override;
126 void focusOutEvent(QFocusEvent *ev) override;
127 bool focusNextPrevChild(bool next) override;
128
129
130private:
131 Q_DISABLE_COPY(QLabel)
132 Q_DECLARE_PRIVATE(QLabel)
133 friend class QTipLabel;
134 friend class QMessageBoxPrivate;
135 friend class QBalloonTip;
136};
137
138QT_END_NAMESPACE
139
140#endif // QLABEL_H
The QApplication class manages the GUI application's control flow and main settings.
The QGroupBox widget provides a group box frame with a title.
Definition qgroupbox.h:17
QScopedPointer< QImageIOHandlerPrivate > d_ptr
The QInputDialog class provides a simple convenience dialog to get a single value from the user.
The QLabel widget provides a text or image display.
Definition qlabel.h:20
The QMessageBox class provides a modal dialog for informing the user or for asking the user a questio...
Definition qmessagebox.h:22
The QPaintEngineState class provides information about the active paint engine's current state....
\inmodule QtGui
virtual QPixmap createPixmap(QSize size)
friend class QPainter
void setSystemRect(const QRect &rect)
void setActive(bool newState)
Sets the active state of the paint engine to state.
virtual void drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode)
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual QPixmap createPixmapFromImage(QImage image, Qt::ImageConversionFlags flags=Qt::AutoColor)
friend class QWidgetPrivate
QRect systemRect() const
QPaintEngine(PaintEngineFeatures features=PaintEngineFeatures())
Creates a paint engine with the featureset specified by caps.
friend class QFontEngineQPF2
friend class QMacCGContext
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem)
This function draws the text item textItem at position p.
virtual void drawLines(const QLineF *lines, int lineCount)
The default implementation splits the list of lines in lines into lineCount separate calls to drawPat...
PolygonDrawMode
\value OddEvenMode The polygon should be drawn using OddEven fill rule.
virtual void drawPoints(const QPointF *points, int pointCount)
Draws the first pointCount points in the buffer points.
virtual void drawRects(const QRectF *rects, int rectCount)
Draws the first rectCount rectangles in the buffer rects.
virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags=Qt::AutoColor)
Reimplement this function to draw the part of the image specified by the sr rectangle in the given re...
QPainter * painter() const
Returns the paint engine's painter.
void fix_neg_rect(int *x, int *y, int *w, int *h)
void setPaintDevice(QPaintDevice *device)
virtual QPoint coordinateOffset() const
virtual void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode)
Reimplement this virtual function to draw the polygon defined by the pointCount first points in point...
void setDirty(DirtyFlags df)
void setSystemClip(const QRegion &baseClip)
QPaintEngineState * state
friend class QPainterReplayer
friend class QX11GLPlatformPixmap
PaintEngineFeatures gccaps
void clearDirty(DirtyFlags df)
bool hasFeature(PaintEngineFeatures feature) const
Returns true if the paint engine supports the specified feature; otherwise returns false.
virtual void drawEllipse(const QRectF &r)
Reimplement this function to draw the largest ellipse that can be contained within rectangle rect.
QRegion systemClip() const
bool isExtended() const
QPaintDevice * paintDevice() const
Returns the device that this engine is painting on, if painting is active; otherwise returns \nullptr...
bool testDirty(DirtyFlags df)
virtual void updateState(const QPaintEngineState &state)=0
Reimplement this function to update the state of a paint engine.
DirtyFlag
\value DirtyPen The pen is dirty and needs to be updated.
Type
\value X11 \value Windows \value MacPrinter \value CoreGraphics \macos's Quartz2D (CoreGraphics) \val...
virtual Type type() const =0
Reimplement this function to return the paint engine \l{Type}.
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling.
bool begin(QPaintDevice *)
Begins painting the paint device and returns true if successful; otherwise returns false.
void drawRects(const QRectF *rects, int rectCount)
Draws the first rectCount of the given rectangles using the current pen and brush.
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
friend class QFontEngineMac
Definition qpainter.h:427
friend class QWin32PaintEngine
Definition qpainter.h:432
friend class QWin32PaintEnginePrivate
Definition qpainter.h:433
friend class QWidget
Definition qpainter.h:423
friend class QFontEngineWin
Definition qpainter.h:428
void drawEllipse(const QRectF &r)
Draws the ellipse defined by the given rectangle.
bool end()
Ends painting.
void drawPoints(const QPointF *points, int pointCount)
Draws the first pointCount points in the array points using the current pen's color.
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false.
\inmodule QtGui
\inmodule QtCore\reentrant
Definition qpoint.h:229
The QPolygonF class provides a list of points using floating point precision.
Definition qpolygon.h:96
The QRadioButton widget provides a radio button with a text label.
The QStyleHintReturnMask class provides style hints that return a QRegion.
The QStyleHintReturnVariant class provides style hints that return a QVariant.
\variable QStyleOptionGraphicsItem::exposedRect
\variable QStyleOptionHeaderV2::textElideMode
\variable QStyleOptionMenuItem::menuItemType
\variable QStyleOptionComplex::subControls
\variable QStyleOption::palette
\variable QStyleOptionFocusRect::backgroundColor
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
\variable QStyleOptionFrame::features
The QStyleOptionHeaderV2 class is used to describe the parameters for drawing a header.
\variable QStyleOptionProgressBar::minimum
\variable QStyleOptionToolBox::selectedPosition
\variable QStyleOptionComboBox::editable
\variable QStyleOptionDockWidget::title
The QStyleOption class stores the parameters used by QStyle functions.
The QTextEdit class provides a widget that is used to edit and display both plain and rich text.
Definition qtextedit.h:27
Internal QTextItem.
\inmodule QtGui
uint is_closing
Definition qwidget.h:82
QPalette pal
Definition qwidget.h:91
uint focus_policy
Definition qwidget.h:80
uint in_show
Definition qwidget.h:83
uint unused
Definition qwidget.h:89
uint fstrut_dirty
Definition qwidget.h:85
QRect wrect
Definition qwidget.h:93
QRect crect
Definition qwidget.h:90
uint in_destructor
Definition qwidget.h:88
uint sizehint_forced
Definition qwidget.h:81
uint in_set_window_state
Definition qwidget.h:84
Qt::WindowFlags window_flags
Definition qwidget.h:78
QFont fnt
Definition qwidget.h:92
uint window_modality
Definition qwidget.h:87
uint window_state
Definition qwidget.h:79
WId winid
Definition qwidget.h:76
uint context_menu_policy
Definition qwidget.h:86
uint widget_attributes
Definition qwidget.h:77
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
The QWindows11Style class provides a look and feel suitable for applications on Microsoft Windows 11.
void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override
void unpolish(QWidget *widget) override
void polish(QWidget *widget) override
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const override
QSize sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const override
QRect subControlRect(ComplexControl control, const QStyleOptionComplex *option, SubControl subControl, const QWidget *widget) const override
QWindows11Style(QWindows11StylePrivate &dd)
void polish(QPalette &pal) override
int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
int styleHint(StyleHint hint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const override
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override
QRect subElementRect(QStyle::SubElement element, const QStyleOption *option, const QWidget *widget=nullptr) const override
~QWindows11Style() override
Destructor.
HRGN mask(QWidget *widget)
QWindowsThemeData(const QWidget *w=nullptr, QPainter *p=nullptr, int themeIn=-1, int part=0, int state=0, const QRect &r=QRect())
QMarginsF margins(const QRect &rect, int propId=TMT_CONTENTMARGINS)
const QWidget * widget
static RECT toRECT(const QRect &qr)
QMarginsF margins(int propId=TMT_CONTENTMARGINS)
static QSizeF themeSize(const QWidget *w=nullptr, QPainter *p=nullptr, int themeIn=-1, int part=0, int state=0)
HBITMAP buffer(int w=0, int h=0)
static int fixedPixelMetric(QStyle::PixelMetric pm)
static HDC hdcForWidgetBackingStore(const QWidget *widget)
static QBackingStore * backingStoreForWidget(const QWidget *widget)
bool swapAlphaChannel(const QRect &rect, bool allPixels=false)
bool drawBackgroundThruNativeBuffer(QWindowsThemeData &QWindowsThemeData, qreal aditionalDevicePixelRatio, qreal correctionFactor)
static HWND winId(const QWidget *widget)
void init(bool force=false)
static bool isLineEditBaseColorSet(const QStyleOption *option, const QWidget *widget)
bool drawBackgroundDirectly(HDC dc, QWindowsThemeData &QWindowsThemeData, qreal aditionalDevicePixelRatio)
static bool isItemViewDelegateLineEdit(const QWidget *widget)
static bool useVista(bool update=false)
bool fixAlphaChannel(const QRect &rect)
void cleanup(bool force=false)
bool isTransparent(QWindowsThemeData &QWindowsThemeData)
bool hasAlphaChannel(const QRect &rect)
QRegion region(QWindowsThemeData &QWindowsThemeData)
bool drawBackground(QWindowsThemeData &QWindowsThemeData, qreal correctionFactor=1)
static HTHEME createTheme(int theme, const QWidget *widget)
static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option=nullptr, const QWidget *widget=nullptr)
static QString themeName(int theme)
The QWindowsVistaStyle class provides a look and feel suitable for applications on Microsoft Windows ...
QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const override
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const override
int styleHint(StyleHint hint, const QStyleOption *opt=nullptr, const QWidget *widget=nullptr, QStyleHintReturn *returnData=nullptr) const override
SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option, const QPoint &pos, const QWidget *widget=nullptr) const override
void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const override
void polish(QWidget *widget) override
int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget=nullptr) const override
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const override
\reimp
~QWindowsVistaStyle() override
Destructor.
void polish(QPalette &pal) override
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=nullptr) const override
QSize sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const override
QWindowsVistaStyle(QWindowsVistaStylePrivate &dd)
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const override
void unpolish(QWidget *widget) override
Combined button and popup list for selecting options.
Q_DECLARE_TYPEINFO(QByteArrayView, Q_PRIMITIVE_TYPE)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2462
QT_REQUIRE_CONFIG(itemmodel)
T qstyleoption_cast(const QStyleOption *opt)
T qstyleoption_cast(QStyleOption *opt)
bool operator==(const ThemeMapKey &k1, const ThemeMapKey &k2)
@ UnknownAlpha
size_t qHash(const ThemeMapKey &key)
AlphaChannelType alphaType
ThemeMapKey(const QWindowsThemeData &data)
ThemeMapKey()=default