QtBase  v6.3.1
qlabel.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QLABEL_H
41 #define QLABEL_H
42 
43 #include <QtWidgets/qtwidgetsglobal.h>
44 #include <QtWidgets/qframe.h>
45 #include <QtGui/qpicture.h>
46 #include <QtGui/qtextdocument.h>
47 
49 
51 
52 
53 class QLabelPrivate;
54 
55 class Q_WIDGETS_EXPORT QLabel : public QFrame
56 {
57  Q_OBJECT
58  Q_PROPERTY(QString text READ text WRITE setText)
59  Q_PROPERTY(Qt::TextFormat textFormat READ textFormat WRITE setTextFormat)
61  Q_PROPERTY(bool scaledContents READ hasScaledContents WRITE setScaledContents)
63  Q_PROPERTY(bool wordWrap READ wordWrap WRITE setWordWrap)
64  Q_PROPERTY(int margin READ margin WRITE setMargin)
65  Q_PROPERTY(int indent READ indent WRITE setIndent)
66  Q_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks)
67  Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags
68  WRITE setTextInteractionFlags)
69  Q_PROPERTY(bool hasSelectedText READ hasSelectedText)
70  Q_PROPERTY(QString selectedText READ selectedText)
71 
72 public:
73  explicit QLabel(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags());
74  explicit QLabel(const QString &text, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags());
75  ~QLabel();
76 
77  QString text() const;
78 
79 #if QT_DEPRECATED_SINCE(6,6)
80  QPixmap pixmap(Qt::ReturnByValueConstant) const { return pixmap(); }
81 #endif
82  QPixmap pixmap() const;
83 
84 #ifndef QT_NO_PICTURE
85 #if QT_DEPRECATED_SINCE(6,6)
87 #endif
88  QPicture picture() const;
89 #endif
90 #if QT_CONFIG(movie)
91  QMovie *movie() const;
92 #endif
93 
94  Qt::TextFormat textFormat() const;
95  void setTextFormat(Qt::TextFormat);
96 
97  QTextDocument::ResourceProvider resourceProvider() const;
98  void setResourceProvider(const QTextDocument::ResourceProvider &provider);
99 
100  Qt::Alignment alignment() const;
102 
103  void setWordWrap(bool on);
104  bool wordWrap() const;
105 
106  int indent() const;
107  void setIndent(int);
108 
109  int margin() const;
110  void setMargin(int);
111 
112  bool hasScaledContents() const;
113  void setScaledContents(bool);
114  QSize sizeHint() const override;
115  QSize minimumSizeHint() const override;
116 #ifndef QT_NO_SHORTCUT
117  void setBuddy(QWidget *);
118  QWidget *buddy() const;
119 #endif
120  int heightForWidth(int) const override;
121 
122  bool openExternalLinks() const;
123  void setOpenExternalLinks(bool open);
124 
125  void setTextInteractionFlags(Qt::TextInteractionFlags flags);
126  Qt::TextInteractionFlags textInteractionFlags() const;
127 
128  void setSelection(int, int);
129  bool hasSelectedText() const;
130  QString selectedText() const;
131  int selectionStart() const;
132 
133 public Q_SLOTS:
134  void setText(const QString &);
135  void setPixmap(const QPixmap &);
136 #ifndef QT_NO_PICTURE
137  void setPicture(const QPicture &);
138 #endif
139 #if QT_CONFIG(movie)
140  void setMovie(QMovie *movie);
141 #endif
142  void setNum(int);
143  void setNum(double);
144  void clear();
145 
146 Q_SIGNALS:
147  void linkActivated(const QString& link);
148  void linkHovered(const QString& link);
149 
150 protected:
151  bool event(QEvent *e) override;
152  void keyPressEvent(QKeyEvent *ev) override;
153  void paintEvent(QPaintEvent *) override;
154  void changeEvent(QEvent *) override;
155  void mousePressEvent(QMouseEvent *ev) override;
156  void mouseMoveEvent(QMouseEvent *ev) override;
157  void mouseReleaseEvent(QMouseEvent *ev) override;
158 #ifndef QT_NO_CONTEXTMENU
159  void contextMenuEvent(QContextMenuEvent *ev) override;
160 #endif // QT_NO_CONTEXTMENU
161  void focusInEvent(QFocusEvent *ev) override;
162  void focusOutEvent(QFocusEvent *ev) override;
163  bool focusNextPrevChild(bool next) override;
164 
165 
166 private:
168  Q_DECLARE_PRIVATE(QLabel)
169 #if QT_CONFIG(movie)
170  Q_PRIVATE_SLOT(d_func(), void _q_movieUpdated(const QRect&))
171  Q_PRIVATE_SLOT(d_func(), void _q_movieResized(const QSize&))
172 #endif
173  Q_PRIVATE_SLOT(d_func(), void _q_linkHovered(const QString &))
174 
175 #ifndef QT_NO_SHORTCUT
176  Q_PRIVATE_SLOT(d_func(), void _q_buddyDeleted())
177 #endif
178  friend class QTipLabel;
179  friend class QMessageBoxPrivate;
180  friend class QBalloonTip;
181 };
182 
184 
185 #endif // QLABEL_H
The QContextMenuEvent class contains parameters that describe a context menu event....
Definition: qevent.h:665
The QEvent class is the base class of all event classes. Event objects contain event parameters.
Definition: qcoreevent.h:58
The QFocusEvent class contains event parameters for widget focus events. \inmodule QtGui.
Definition: qevent.h:520
The QFrame class is the base class of widgets that can have a frame.
Definition: qframe.h:53
QSize sizeHint() const override
Definition: qframe.cpp:493
bool event(QEvent *e) override
Definition: qframe.cpp:546
void paintEvent(QPaintEvent *) override
Definition: qframe.cpp:512
void changeEvent(QEvent *) override
Definition: qframe.cpp:533
The QKeyEvent class describes a key event.
Definition: qevent.h:471
The QLabel widget provides a text or image display.
Definition: qlabel.h:56
void linkActivated(const QString &link)
void linkHovered(const QString &link)
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:231
The QMovie class is a convenience class for playing movies with QImageReader.
Definition: qmovie.h:64
The QPaintEvent class contains event parameters for paint events. \inmodule QtGui.
Definition: qevent.h:539
The QPicture class is a paint device that records and replays QPainter commands.
Definition: qpicture.h:55
The QPixmap class is an off-screen image representation that can be used as a paint device.
Definition: qpixmap.h:63
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
The QString class provides a Unicode character string.
Definition: qstring.h:388
std::function< QVariant(const QUrl &)> ResourceProvider
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
virtual void mouseMoveEvent(QMouseEvent *event)
Definition: qwidget.cpp:9362
virtual void mousePressEvent(QMouseEvent *event)
Definition: qwidget.cpp:9384
virtual void focusInEvent(QFocusEvent *event)
Definition: qwidget.cpp:9566
virtual void mouseReleaseEvent(QMouseEvent *event)
Definition: qwidget.cpp:9409
QSize minimumSizeHint
the recommended minimum size for the widget
Definition: qwidget.h:183
virtual bool focusNextPrevChild(bool next)
Definition: qwidget.cpp:6759
virtual void focusOutEvent(QFocusEvent *event)
Definition: qwidget.cpp:9592
virtual void keyPressEvent(QKeyEvent *event)
Definition: qwidget.cpp:9507
virtual void contextMenuEvent(QContextMenuEvent *event)
Definition: qwidget.cpp:9781
virtual int heightForWidth(int) const
Definition: qwidget.cpp:10282
b clear()
double e
uint alignment
union Alignment_ Alignment
short next
Definition: keywords.cpp:454
TextFormat
Definition: qnamespace.h:1204
ReturnByValueConstant
Definition: qnamespace.h:1733
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
@ text
QT_REQUIRE_CONFIG(label)
GLfloat GLfloat f
GLuint GLsizei const GLchar * label
[43]
GLbitfield flags
#define Q_PROPERTY(...)
Definition: qtmetamacros.h:92
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_SLOTS
Definition: qtmetamacros.h:80
#define Q_PRIVATE_SLOT(d, signature)
Definition: qtmetamacros.h:82
#define Q_SIGNALS
Definition: qtmetamacros.h:81
label setAlignment(Qt::AlignLeft|Qt::AlignTop)
[0]
file open(QIODevice::ReadOnly)
MyClass setText
nameLabel setBuddy(nameLineEdit)
widget render & pixmap
imageLabel setPixmap(QPixmap::fromImage(image))
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent