Qt 4.8
qlabel.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui 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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QLABEL_H
43 #define QLABEL_H
44 
45 #include <QtGui/qframe.h>
46 
48 
50 
51 QT_MODULE(Gui)
52 
53 class QLabelPrivate;
54 
55 class Q_GUI_EXPORT QLabel : public QFrame
56 {
57  Q_OBJECT
62  Qt::Alignment alignment;
63  bool wordWrap;
64  int margin;
65  int indent;
67  Qt::TextInteractionFlags textInteractionFlags;
70 
71 public:
72  explicit QLabel(QWidget *parent=0, Qt::WindowFlags f=0);
73  explicit QLabel(const QString &text, QWidget *parent=0, Qt::WindowFlags f=0);
74  ~QLabel();
75 
76  QString text() const;
77  const QPixmap *pixmap() const;
78 #ifndef QT_NO_PICTURE
79  const QPicture *picture() const;
80 #endif
81 #ifndef QT_NO_MOVIE
82  QMovie *movie() const;
83 #endif
84 
85  Qt::TextFormat textFormat() const;
86  void setTextFormat(Qt::TextFormat);
87 
88  Qt::Alignment alignment() const;
89  void setAlignment(Qt::Alignment);
90 
91  void setWordWrap(bool on);
92  bool wordWrap() const;
93 
94  int indent() const;
95  void setIndent(int);
96 
97  int margin() const;
98  void setMargin(int);
99 
100  bool hasScaledContents() const;
101  void setScaledContents(bool);
102  QSize sizeHint() const;
103  QSize minimumSizeHint() const;
104 #ifndef QT_NO_SHORTCUT
105  void setBuddy(QWidget *);
106  QWidget *buddy() const;
107 #endif
108  int heightForWidth(int) const;
109 
110  bool openExternalLinks() const;
111  void setOpenExternalLinks(bool open);
112 
113  void setTextInteractionFlags(Qt::TextInteractionFlags flags);
114  Qt::TextInteractionFlags textInteractionFlags() const;
115 
116  void setSelection(int, int);
117  bool hasSelectedText() const;
118  QString selectedText() const;
119  int selectionStart() const;
120 
121 public Q_SLOTS:
122  void setText(const QString &);
123  void setPixmap(const QPixmap &);
124 #ifndef QT_NO_PICTURE
125  void setPicture(const QPicture &);
126 #endif
127 #ifndef QT_NO_MOVIE
128  void setMovie(QMovie *movie);
129 #endif
130  void setNum(int);
131  void setNum(double);
132  void clear();
133 
134 Q_SIGNALS:
135  void linkActivated(const QString& link);
136  void linkHovered(const QString& link);
137 
138 protected:
139  bool event(QEvent *e);
140  void keyPressEvent(QKeyEvent *ev);
141  void paintEvent(QPaintEvent *);
142  void changeEvent(QEvent *);
143  void mousePressEvent(QMouseEvent *ev);
144  void mouseMoveEvent(QMouseEvent *ev);
145  void mouseReleaseEvent(QMouseEvent *ev);
147  void focusInEvent(QFocusEvent *ev);
148  void focusOutEvent(QFocusEvent *ev);
149  bool focusNextPrevChild(bool next);
150 
151 public:
152 #ifdef QT3_SUPPORT
153  QT3_SUPPORT_CONSTRUCTOR QLabel(QWidget *parent, const char* name, Qt::WindowFlags f=0);
154  QT3_SUPPORT_CONSTRUCTOR QLabel(const QString &text, QWidget *parent, const char* name,
155  Qt::WindowFlags f=0);
156  QT3_SUPPORT_CONSTRUCTOR QLabel(QWidget *buddy, const QString &,
157  QWidget *parent=0, const char* name=0, Qt::WindowFlags f=0);
158  QT3_SUPPORT void setAlignment(int alignment);
159 
160  // don't mark the next function with QT3_SUPPORT
161  inline void setAlignment(Qt::AlignmentFlag flag) { setAlignment((Qt::Alignment)flag); }
162 #endif
163 
164 private:
167 #ifndef QT_NO_MOVIE
168  Q_PRIVATE_SLOT(d_func(), void _q_movieUpdated(const QRect&))
169  Q_PRIVATE_SLOT(d_func(), void _q_movieResized(const QSize&))
170 #endif
171  Q_PRIVATE_SLOT(d_func(), void _q_linkHovered(const QString &))
172 
173  friend class QTipLabel;
176 };
177 
179 
181 
182 #endif // QLABEL_H
void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
Definition: qframe.cpp:527
The QKeyEvent class describes a key event.
Definition: qevent.h:224
bool wordWrap
the label&#39;s word-wrapping policy
Definition: qlabel.h:63
virtual int heightForWidth(int) const
Returns the preferred height for this widget, given the width w.
Definition: qwidget.cpp:10241
int margin
the width of the margin
Definition: qlabel.h:64
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QMovie class is a convenience class for playing movies with QImageReader.
Definition: qmovie.h:74
#define QT_MODULE(x)
Definition: qglobal.h:2783
Qt::TextFormat textFormat
the label&#39;s text format
Definition: qlabel.h:59
virtual QSize minimumSizeHint() const
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QContextMenuEvent class contains parameters that describe a context menu event.
Definition: qevent.h:396
virtual void mouseReleaseEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
Definition: qwidget.cpp:9286
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
virtual void mousePressEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition: qwidget.cpp:9261
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
int indent
the label&#39;s text indent in pixels
Definition: qlabel.h:65
#define Q_SIGNALS
Definition: qobjectdefs.h:72
virtual void focusOutEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) f...
Definition: qwidget.cpp:9457
Qt::TextInteractionFlags textInteractionFlags
Specifies how the label should interact with user input if it displays text.
Definition: qlabel.h:67
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool scaledContents
whether the label will scale its contents to fill all available space.
Definition: qlabel.h:61
void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qframe.cpp:574
const char * name
Qt::Alignment alignment
the alignment of the label&#39;s contents
Definition: qlabel.h:62
virtual void keyPressEvent(QKeyEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
Definition: qwidget.cpp:9375
#define Q_OBJECT
Definition: qobjectdefs.h:157
TextFormat
Definition: qnamespace.h:1310
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
virtual void contextMenuEvent(QContextMenuEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive widget context men...
Definition: qwidget.cpp:9645
bool event(QEvent *e)
Reimplemented Function
Definition: qframe.cpp:587
virtual bool focusNextPrevChild(bool next)
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns true if it can find a new widget, or false if it can&#39;t.
Definition: qwidget.cpp:6836
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QLabel widget provides a text or image display.
Definition: qlabel.h:55
QPixmap pixmap
the label&#39;s pixmap
Definition: qlabel.h:60
bool openExternalLinks
Specifies whether QLabel should automatically open links using QDesktopServices::openUrl() instead of...
Definition: qlabel.h:66
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QSize sizeHint() const
em>Reimplemented Function
Definition: qframe.cpp:508
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
virtual void mouseMoveEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition: qwidget.cpp:9239
QString text
the label&#39;s text
Definition: qlabel.h:58
#define class
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
AlignmentFlag
Definition: qnamespace.h:208
The QPicture class is a paint device that records and replays QPainter commands.
Definition: qpicture.h:58
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
bool hasSelectedText
whether there is any text selected
Definition: qlabel.h:68
The QFrame class is the base class of widgets that can have a frame.
Definition: qframe.h:55
#define QT_END_HEADER
Definition: qglobal.h:137
virtual void focusInEvent(QFocusEvent *)
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus receive...
Definition: qwidget.cpp:9431
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
int open(const char *, int,...)
#define text
Definition: qobjectdefs.h:80
QString selectedText
the selected text
Definition: qlabel.h:69