CopperSpice API  1.9.2
QLabel Class Reference

The QLabel widget provides a text or image display. More...

Inheritance diagram for QLabel:
QFrame QWidget QObject QPaintDevice

Public Signals

void linkActivated (const QString &link)
 
void linkHovered (const QString &link)
 
- Public Signals inherited from QWidget
void customContextMenuRequested (const QPoint &pos)
 
void windowIconChanged (const QIcon &icon)
 
void windowIconTextChanged (const QString &iconText)
 
void windowTitleChanged (const QString &title)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

void clear ()
 
void setMovie (QMovie *movie)
 
void setNum (double num)
 
void setNum (int num)
 
void setPicture (const QPicture &picture)
 
void setPixmap (const QPixmap &pixmap)
 
void setText (const QString &text)
 
- Public Slots inherited from QWidget
bool close ()
 
void hide ()
 
void lower ()
 
void raise ()
 
void repaint ()
 
void setDisabled (bool disable)
 
void setEnabled (bool enable)
 
void setFocus ()
 
void setHidden (bool hidden)
 
void setStyleSheet (const QString &styleSheet)
 
virtual void setVisible (bool visible)
 
void setWindowModified (bool modified)
 
void setWindowTitle (const QString &title)
 
void show ()
 
void showFullScreen ()
 
void showMaximized ()
 
void showMinimized ()
 
void showNormal ()
 
void update ()
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QLabel (const QString &text, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 QLabel (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 ~QLabel ()
 
Qt::Alignment alignment () const
 
QWidgetbuddy () const
 
bool hasScaledContents () const
 
bool hasSelectedText () const
 
int heightForWidth (int width) const override
 
int indent () const
 
int margin () const
 
QSize minimumSizeHint () const override
 
QMoviemovie () const
 
bool openExternalLinks () const
 
const QPicturepicture () const
 
const QPixmappixmap () const
 
QString selectedText () const
 
int selectionStart () const
 
void setAlignment (Qt::Alignment alignment)
 
void setBuddy (QWidget *buddy)
 
void setIndent (int indent)
 
void setMargin (int margin)
 
void setOpenExternalLinks (bool open)
 
void setScaledContents (bool enabled)
 
void setSelection (int start, int length)
 
void setTextFormat (Qt::TextFormat format)
 
void setTextInteractionFlags (Qt::TextInteractionFlags flags)
 
void setWordWrap (bool enabled)
 
QSize sizeHint () const override
 
QString text () const
 
Qt::TextFormat textFormat () const
 
Qt::TextInteractionFlags textInteractionFlags () const
 
bool wordWrap () const
 
- Public Methods inherited from QFrame
 QFrame (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 ~QFrame ()
 
QRect frameRect () const
 
Shadow frameShadow () const
 
Shape frameShape () const
 
int frameStyle () const
 
int frameWidth () const
 
int lineWidth () const
 
int midLineWidth () const
 
void setFrameRect (const QRect &rect)
 
void setFrameShadow (Shadow value)
 
void setFrameShape (Shape value)
 
void setFrameStyle (int style)
 
void setLineWidth (int width)
 
void setMidLineWidth (int width)
 
- Public Methods inherited from QWidget
 QWidget (QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
 ~QWidget ()
 
bool acceptDrops () const
 
QString accessibleDescription () const
 
QString accessibleName () const
 
QList< QAction * > actions () const
 
void activateWindow ()
 
void addAction (QAction *action)
 
void addActions (const QList< QAction * > &actions)
 
void adjustSize ()
 
bool autoFillBackground () const
 
QPalette::ColorRole backgroundRole () const
 
QBackingStorebackingStore () const
 
QSize baseSize () const
 
QWidget * childAt (const QPoint &position) const
 
QWidget * childAt (int x, int y) const
 
QRect childrenRect () const
 
QRegion childrenRegion () const
 
void clearFocus ()
 
void clearMask ()
 
QMargins contentsMargins () const
 
QRect contentsRect () const
 
Qt::ContextMenuPolicy contextMenuPolicy () const
 
QCursor cursor () const
 
WId effectiveWinId () const
 
void ensurePolished () const
 
Qt::FocusPolicy focusPolicy () const
 
QWidget * focusProxy () const
 
QWidget * focusWidget () const
 
const QFontfont () const
 
QFontInfo fontInfo () const
 
QFontMetrics fontMetrics () const
 
QPalette::ColorRole foregroundRole () const
 
QRect frameGeometry () const
 
QSize frameSize () const
 
const QRectgeometry () const
 
void getContentsMargins (int *left, int *top, int *right, int *bottom) const
 
QPixmap grab (const QRect &rectangle=QRect (QPoint (0, 0), QSize (-1,-1)))
 
void grabGesture (Qt::GestureType gestureType, Qt::GestureFlags flags=Qt::GestureFlags ())
 
void grabKeyboard ()
 
void grabMouse ()
 
void grabMouse (const QCursor &cursor)
 
int grabShortcut (const QKeySequence &key, Qt::ShortcutContext context=Qt::WindowShortcut)
 
QGraphicsEffectgraphicsEffect () const
 
QGraphicsProxyWidgetgraphicsProxyWidget () const
 
bool hasEditFocus () const
 
bool hasFocus () const
 
virtual bool hasHeightForWidth () const
 
bool hasMouseTracking () const
 
int height () const
 
Qt::InputMethodHints inputMethodHints () const
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
void insertAction (QAction *before, QAction *action)
 
void insertActions (QAction *before, QList< QAction * > actions)
 
bool isActiveWindow () const
 
bool isAncestorOf (const QWidget *child) const
 
bool isEnabled () const
 
bool isEnabledTo (const QWidget *parent) const
 
bool isEnabledToTLW () const
 
bool isFullScreen () const
 
bool isHidden () const
 
bool isMaximized () const
 
bool isMinimized () const
 
bool isModal () const
 
bool isTopLevel () const
 
bool isVisible () const
 
bool isVisibleTo (const QWidget *parent) const
 
bool isWindow () const
 
bool isWindowModified () const
 
QLayoutlayout () const
 
Qt::LayoutDirection layoutDirection () const
 
QLocale locale () const
 
QPoint mapFrom (const QWidget *parent, const QPoint &pos) const
 
QPoint mapFromGlobal (const QPoint &pos) const
 
QPoint mapFromParent (const QPoint &pos) const
 
QPoint mapTo (const QWidget *parent, const QPoint &pos) const
 
QPoint mapToGlobal (const QPoint &pos) const
 
QPoint mapToParent (const QPoint &pos) const
 
QRegion mask () const
 
int maximumHeight () const
 
QSize maximumSize () const
 
int maximumWidth () const
 
int minimumHeight () const
 
QSize minimumSize () const
 
int minimumWidth () const
 
void move (const QPoint &point)
 
void move (int x, int y)
 
QWidget * nativeParentWidget () const
 
QWidget * nextInFocusChain () const
 
QRect normalGeometry () const
 
void overrideWindowFlags (Qt::WindowFlags flags)
 
QPaintEnginepaintEngine () const override
 
const QPalettepalette () const
 
QWidget * parentWidget () const
 
QPoint pos () const
 
QWidget * previousInFocusChain () const
 
QRect rect () const
 
void releaseKeyboard ()
 
void releaseMouse ()
 
void releaseShortcut (int id)
 
void removeAction (QAction *action)
 
void render (QPaintDevice *target, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void render (QPainter *painter, const QPoint &targetOffset=QPoint (), const QRegion &sourceRegion=QRegion (), RenderFlags renderFlags=RenderFlags (DrawWindowBackground|DrawChildren))
 
void repaint (const QRect &rect)
 
void repaint (const QRegion &region)
 
void repaint (int x, int y, int w, int h)
 
void resize (const QSize &size)
 
void resize (int w, int h)
 
bool restoreGeometry (const QByteArray &geometry)
 
QByteArray saveGeometry () const
 
void scroll (int dx, int dy)
 
void scroll (int dx, int dy, const QRect &rect)
 
void setAcceptDrops (bool on)
 
void setAccessibleDescription (const QString &description)
 
void setAccessibleName (const QString &name)
 
void setAttribute (Qt::WidgetAttribute attribute, bool enable=true)
 
void setAutoFillBackground (bool enable)
 
void setBackgroundRole (QPalette::ColorRole role)
 
void setBaseSize (const QSize &size)
 
void setBaseSize (int basew, int baseh)
 
void setContentsMargins (const QMargins &margins)
 
void setContentsMargins (int left, int top, int right, int bottom)
 
void setContextMenuPolicy (Qt::ContextMenuPolicy policy)
 
void setCursor (const QCursor &cursor)
 
void setEditFocus (bool enable)
 
void setFixedHeight (int h)
 
void setFixedSize (const QSize &size)
 
void setFixedSize (int w, int h)
 
void setFixedWidth (int w)
 
void setFocus (Qt::FocusReason reason)
 
void setFocusPolicy (Qt::FocusPolicy policy)
 
void setFocusProxy (QWidget *widget)
 
void setFont (const QFont &font)
 
void setForegroundRole (QPalette::ColorRole role)
 
void setGeometry (const QRect &rect)
 
void setGeometry (int x, int y, int w, int h)
 
void setGraphicsEffect (QGraphicsEffect *effect)
 
void setInputMethodHints (Qt::InputMethodHints hints)
 
void setLayout (QLayout *layout)
 
void setLayoutDirection (Qt::LayoutDirection direction)
 
void setLocale (const QLocale &locale)
 
void setMask (const QBitmap &bitmap)
 
void setMask (const QRegion &region)
 
void setMaximumHeight (int maxh)
 
void setMaximumSize (const QSize &size)
 
void setMaximumSize (int maxw, int maxh)
 
void setMaximumWidth (int maxw)
 
void setMinimumHeight (int minh)
 
void setMinimumSize (const QSize &size)
 
void setMinimumSize (int minw, int minh)
 
void setMinimumWidth (int minw)
 
void setMouseTracking (bool enable)
 
void setPalette (const QPalette &palette)
 
void setParent (QWidget *parent)
 
void setParent (QWidget *parent, Qt::WindowFlags flags)
 
void setShortcutAutoRepeat (int id, bool enable=true)
 
void setShortcutEnabled (int id, bool enable=true)
 
void setSizeIncrement (const QSize &size)
 
void setSizeIncrement (int w, int h)
 
void setSizePolicy (QSizePolicy policy)
 
void setSizePolicy (QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical)
 
void setStatusTip (const QString &data)
 
void setStyle (QStyle *style)
 
void setToolTip (const QString &data)
 
void setToolTipDuration (int msec)
 
void setUpdatesEnabled (bool enable)
 
void setWhatsThis (const QString &str)
 
void setWindowFilePath (const QString &filePath)
 
void setWindowFlags (Qt::WindowFlags flags)
 
void setWindowIcon (const QIcon &icon)
 
void setWindowModality (Qt::WindowModality windowModality)
 
void setWindowOpacity (qreal level)
 
void setWindowRole (const QString &role)
 
void setWindowState (Qt::WindowStates windowState)
 
QSize size () const
 
QSize sizeIncrement () const
 
QSizePolicy sizePolicy () const
 
void stackUnder (QWidget *widget)
 
QString statusTip () const
 
QStylestyle () const
 
QString styleSheet () const
 
bool testAttribute (Qt::WidgetAttribute attribute) const
 
QString toolTip () const
 
int toolTipDuration () const
 
QWidget * topLevelWidget () const
 
bool underMouse () const
 
void ungrabGesture (Qt::GestureType gestureType)
 
void unsetCursor ()
 
void unsetLayoutDirection ()
 
void unsetLocale ()
 
void update (const QRect &rect)
 
void update (const QRegion &region)
 
void update (int x, int y, int w, int h)
 
void updateGeometry ()
 
bool updatesEnabled () const
 
QRegion visibleRegion () const
 
QString whatsThis () const
 
int width () const
 
QWidget * window () const
 
QString windowFilePath () const
 
Qt::WindowFlags windowFlags () const
 
QWindowwindowHandle () const
 
QIcon windowIcon () const
 
Qt::WindowModality windowModality () const
 
qreal windowOpacity () const
 
QString windowRole () const
 
Qt::WindowStates windowState () const
 
QString windowTitle () const
 
Qt::WindowType windowType () const
 
WId winId () const
 
int x () const
 
int y () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 
- Public Methods inherited from QPaintDevice
virtual ~QPaintDevice ()
 
int colorCount () const
 
int depth () const
 
int devicePixelRatio () const
 
qreal devicePixelRatioF () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
int width () const
 
int widthMM () const
 

Protected Methods

void changeEvent (QEvent *event) override
 
void contextMenuEvent (QContextMenuEvent *event) override
 
bool event (QEvent *event) override
 
void focusInEvent (QFocusEvent *event) override
 
bool focusNextPrevChild (bool next) override
 
void focusOutEvent (QFocusEvent *event) override
 
void keyPressEvent (QKeyEvent *event) override
 
void mouseMoveEvent (QMouseEvent *event) override
 
void mousePressEvent (QMouseEvent *event) override
 
void mouseReleaseEvent (QMouseEvent *event) override
 
void paintEvent (QPaintEvent *event) override
 
- Protected Methods inherited from QFrame
void drawFrame (QPainter *painter)
 
bool event (QEvent *event) override
 
void initStyleOption (QStyleOptionFrame *option) const
 
- Protected Methods inherited from QWidget
virtual void actionEvent (QActionEvent *event)
 
virtual void closeEvent (QCloseEvent *event)
 
void create (WId window=0, bool initializeWindow=true, bool destroyOldWindow=true)
 
void destroy (bool destroyWindow=true, bool destroySubWindows=true)
 
virtual void dragEnterEvent (QDragEnterEvent *event)
 
virtual void dragLeaveEvent (QDragLeaveEvent *event)
 
virtual void dragMoveEvent (QDragMoveEvent *event)
 
virtual void dropEvent (QDropEvent *event)
 
virtual void enterEvent (QEvent *event)
 
bool event (QEvent *event) override
 
bool focusNextChild ()
 
bool focusPreviousChild ()
 
virtual void hideEvent (QHideEvent *event)
 
void initPainter (QPainter *painter) const override
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
virtual void leaveEvent (QEvent *event)
 
int metric (PaintDeviceMetric metric) const override
 
virtual void mouseDoubleClickEvent (QMouseEvent *event)
 
virtual void moveEvent (QMoveEvent *event)
 
virtual bool nativeEvent (const QByteArray &eventType, void *message, long *result)
 
virtual void resizeEvent (QResizeEvent *event)
 
virtual void showEvent (QShowEvent *event)
 
virtual void tabletEvent (QTabletEvent *event)
 
virtual void wheelEvent (QWheelEvent *event)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Protected Methods inherited from QPaintDevice
 QPaintDevice ()
 

Properties

 alignment
 
 hasSelectedText
 
 indent
 
 margin
 
 openExternalLinks
 
 pixmap
 
 scaledContents
 
 selectedText
 
 text
 
 textFormat
 
 textInteractionFlags
 
 wordWrap
 
- Properties inherited from QFrame
 frameRect
 
 frameShadow
 
 frameShape
 
 frameWidth
 
 lineWidth
 
 midLineWidth
 
- Properties inherited from QWidget
 acceptDrops
 
 accessibleDescription
 
 accessibleName
 
 autoFillBackground
 
 baseSize
 
 childrenRect
 
 childrenRegion
 
 contextMenuPolicy
 
 cursor
 
 enabled
 
 focus
 
 focusPolicy
 
 font
 
 frameGeometry
 
 frameSize
 
 fullScreen
 
 geometry
 
 height
 
 inputMethodHints
 
 isActiveWindow
 
 layoutDirection
 
 locale
 
 maximized
 
 maximumHeight
 
 maximumSize
 
 maximumWidth
 
 minimized
 
 minimumHeight
 
 minimumSize
 
 minimumSizeHint
 
 minimumWidth
 
 modal
 
 mouseTracking
 
 normalGeometry
 
 palette
 
 pos
 
 rect
 
 size
 
 sizeHint
 
 sizeIncrement
 
 sizePolicy
 
 statusTip
 
 styleSheet
 
 toolTip
 
 updatesEnabled
 
 visible
 
 whatsThis
 
 width
 
 windowFilePath
 
 windowFlags
 
 windowIcon
 
 windowIconText
 
 windowModality
 
 windowModified
 
 windowOpacity
 
 windowTitle
 
 x
 
 y
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Public Typedefs inherited from QWidget
using RenderFlags = QFlags< RenderFlag >
 
- Public Types inherited from QFrame
enum  Shadow
 
enum  Shape
 
enum  StyleMask
 
- Public Types inherited from QWidget
enum  RenderFlag
 
- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric
 
- Static Public Methods inherited from QWidget
static QWidget * createWindowContainer (QWindow *window, QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::EmptyFlag)
 
static QWidget * find (WId id)
 
static QWidget * keyboardGrabber ()
 
static QWidget * mouseGrabber ()
 
static void setTabOrder (QWidget *firstWidget, QWidget *secondWidget)
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Slots inherited from QWidget
void updateMicroFocus ()
 

Detailed Description

The QLabel widget provides a text or image display. This class is used for displaying text or an image. No user interaction functionality is provided. The visual appearance of the label can be configured in various ways, and it can be used for specifying a focus mnemonic key for another widget.

A QLabel can contain any of the following content types.

ContentSetting
Plain textPass a QString to setText().
Rich textPass a QString that contains rich text to setText().
A pixmapPass a QPixmap to setPixmap().
A moviePass a QMovie to setMovie().
A numberPass an int or a double to setNum(), which converts the number to plain text.
NothingThe same as an empty plain text. This is the default. Set by clear().
Warning
When passing a QString to the constructor or calling setText(), make sure to sanitize your input, as QLabel tries to guess whether it displays the text as plain text or as rich text. You may want to call setTextFormat() explicitly, e.g. in case you expect the text to be in plain format but can not control the text source (for instance when displaying data loaded from the Web).

When the content is changed using any of these functions, any previous content is cleared.

By default, a QLabel displays text and images left aligned and vertically centered. A QLabel can be adjusted and fine-tuned in several ways. The positioning of the content within the QLabel widget area can be tuned with setAlignment() and setIndent(). Text content can also wrap lines along word boundaries with setWordWrap().

For example, this code sets up a sunken panel with a two-line text in the bottom right corner (both lines being flush with the right side of the label):

QLabel *label = new QLabel(this);
label->setFrameStyle(QFrame::Panel | QFrame::Sunken);
label->setText("first line\nsecond line");
label->setAlignment(Qt::AlignBottom | Qt::AlignRight);

The properties and functions QLabel inherits from QFrame can also be used to specify the widget frame to be used for any given label. A QLabel is often used as a label for an interactive widget. For this use QLabel provides a useful mechanism for adding an mnemonic (see QKeySequence) that will set the keyboard focus to the other widget (called the QLabel's "buddy").

QLineEdit* phoneEdit = new QLineEdit(this);
QLabel* phoneLabel = new QLabel("&Phone:", this);
phoneLabel->setBuddy(phoneEdit);

In this example, keyboard focus is transferred to the label's buddy (the QLineEdit) when the user presses Alt+P. If the buddy was a button (inheriting from QAbstractButton), triggering the mnemonic would emulate a button click.

Screenshot of a Windows XP style label A label shown in the Windows XP widget style.
Screenshot of a Mac OS X style label A label shown in the Mac OS X widget style.
Screenshot of a Fusion style label A label shown in the Fusion widget style.
See also
QLineEdit, QTextEdit, QPixmap, QMovie

Constructor & Destructor Documentation

QLabel::QLabel ( QWidget parent = nullptr,
Qt::WindowFlags  flags = Qt::EmptyFlag 
)
explicit

Constructs an empty label. The parent and flags are passed to the QFrame constructor.

See also
setAlignment(), setFrameStyle(), setIndent()
QLabel::QLabel ( const QString text,
QWidget parent = nullptr,
Qt::WindowFlags  flags = Qt::EmptyFlag 
)
explicit

Constructs a label that displays the text. The parent and flags arguments are passed to the QFrame constructor.

See also
setText(), setAlignment(), setFrameStyle(), setIndent()
QLabel::~QLabel ( )

Destroys the label.

Method Documentation

Qt::Alignment QLabel::alignment ( ) const

Returns the value of the property.

QWidget * QLabel::buddy ( ) const

Returns this label's buddy or a nullptr if no buddy is currently set.

See also
setBuddy()
void QLabel::changeEvent ( QEvent event)
overrideprotectedvirtual

Reimplemented from QFrame::changeEvent()

void QLabel::clear ( )
slot

Clears any label contents.

void QLabel::contextMenuEvent ( QContextMenuEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::contextMenuEvent()

bool QLabel::event ( QEvent event)
overrideprotected

Reimplemented from QWidget::event()

void QLabel::focusInEvent ( QFocusEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::focusInEvent()

bool QLabel::focusNextPrevChild ( bool  next)
overrideprotectedvirtual

Reimplemented from QWidget::focusNextPrevChild()

void QLabel::focusOutEvent ( QFocusEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::focusOutEvent()

bool QLabel::hasScaledContents ( ) const

Returns the value of the property.

bool QLabel::hasSelectedText ( ) const

Returns the value of the property.

int QLabel::heightForWidth ( int  width) const
overridevirtual

Reimplemented from QWidget::heightForWidth()

int QLabel::indent ( ) const

Returns the value of the property.

void QLabel::keyPressEvent ( QKeyEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::keyPressEvent()

void QLabel::linkActivated ( const QString link)
signal

This signal is emitted when the user clicks an html link. The link contains the URL.

See also
linkHovered()
void QLabel::linkHovered ( const QString link)
signal

This signal is emitted when the user hovers over an html link. The link contains the URL.

See also
linkActivated()
int QLabel::margin ( ) const

Returns the value of the property.

QSize QLabel::minimumSizeHint ( ) const
overridevirtual

Reimplemented from QWidget::minimumSizeHint()

void QLabel::mouseMoveEvent ( QMouseEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::mouseMoveEvent()

void QLabel::mousePressEvent ( QMouseEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::mousePressEvent()

void QLabel::mouseReleaseEvent ( QMouseEvent event)
overrideprotectedvirtual

Reimplemented from QWidget::mouseReleaseEvent()

QMovie * QLabel::movie ( ) const

Returns a pointer to the label's movie or nullptr if no movie has been set.

See also
setMovie()
bool QLabel::openExternalLinks ( ) const

Returns the value of the property.

void QLabel::paintEvent ( QPaintEvent event)
overrideprotectedvirtual

Reimplemented from QFrame::paintEvent()

const QPicture * QLabel::picture ( ) const

Returns the label's picture or a nullptr if the label does not have a picture.

See also
setPicture()
const QPixmap * QLabel::pixmap ( ) const

Returns the value of the property.

QString QLabel::selectedText ( ) const

Returns the value of the property.

int QLabel::selectionStart ( ) const

This method () returns the index of the first selected character in the label or -1 if no text is selected.

Note
The textInteractionFlags set on the label need to include either TextSelectableByMouse or TextSelectableByKeyboard.
See also
selectedText()
void QLabel::setAlignment ( Qt::Alignment  alignment)

Sets the value of the property to alignment

void QLabel::setBuddy ( QWidget buddy)

Sets this label's buddy to buddy. When the user presses the shortcut key indicated by this label, the keyboard focus is transferred to the label's buddy widget. The buddy mechanism is only available for QLabels that contain text in which one character is prefixed with an ampersand, '&'. This character is set as the shortcut key. Refer to the QKeySequence::mnemonic() documentation for details.

In a dialog you might create two data entry widgets and a label for each, and set up the geometry layout so each label is just to the left of its data entry widget (its "buddy").

QLineEdit *nameEd = new QLineEdit(this);
QLabel *nameLb = new QLabel("&Name:", this);
nameLb->setBuddy(nameEd);
QLineEdit *phoneEd = new QLineEdit(this);
QLabel *phoneLb = new QLabel("&Phone:", this);
phoneLb->setBuddy(phoneEd);
// (layout setup not shown)

With the code above, the focus jumps to the Name field when the user presses Alt+N, and to the Phone field when the user presses Alt+P. To unset a previously set buddy call this method with buddy set to 0.

See also
buddy(), setText(), QShortcut, setAlignment()
void QLabel::setIndent ( int  indent)

Sets the value of the property to indent.

void QLabel::setMargin ( int  margin)

Sets the value of the property to margin.

void QLabel::setMovie ( QMovie movie)
slot

Sets the label contents to movie. Any previous content is cleared. The label does not take ownership of the movie. The buddy shortcut, if any, is disabled.

See also
movie(), setBuddy()
void QLabel::setNum ( double  num)
slot

Sets the label contents to plain text containing the textual representation of double num. Any previous content is cleared. Does nothing if the double's string representation is the same as the current contents of the label.

The buddy shortcut, if any, is disabled.

See also
setText(), QString8::number(), setBuddy()
void QLabel::setNum ( int  num)
slot

Sets the label contents to plain text containing the textual representation of integer num. Any previous content is cleared. Does nothing if the integer's string representation is the same as the current contents of the label.

The buddy shortcut, if any, is disabled.

See also
setText(), QString8::number(), setBuddy()
void QLabel::setOpenExternalLinks ( bool  open)

Sets the value of the property to open.

void QLabel::setPicture ( const QPicture picture)
slot

Sets the label contents to picture. Any previous content is cleared. The buddy shortcut, if any, is disabled.

See also
picture(), setBuddy()
void QLabel::setPixmap ( const QPixmap pixmap)
slot

Sets the value of the property to pixmap.

void QLabel::setScaledContents ( bool  enabled)

Sets the value of the property to enabled.

void QLabel::setSelection ( int  start,
int  length 
)

Selects text from position start and for length characters.

Note
The textInteractionFlags set on the label need to include either TextSelectableByMouse or TextSelectableByKeyboard.
See also
selectedText()
void QLabel::setText ( const QString text)
slot

Sets the value of the property to text.

void QLabel::setTextFormat ( Qt::TextFormat  format)

Sets the value of the property to format.

void QLabel::setTextInteractionFlags ( Qt::TextInteractionFlags  flags)

Sets the value of the property to flags.

void QLabel::setWordWrap ( bool  enabled)

Sets the value of the property to enabled.

QSize QLabel::sizeHint ( ) const
overridevirtual

Reimplemented from QFrame::sizeHint()

QString QLabel::text ( ) const

Returns the value of the property.

Qt::TextFormat QLabel::textFormat ( ) const

Returns the value of the property.

Qt::TextInteractionFlags QLabel::textInteractionFlags ( ) const

Returns the value of the property.

bool QLabel::wordWrap ( ) const

Returns the value of the property.

Property Documentation

QLabel::alignment

This property holds the alignment of the label's contents. By default, the contents of the label are left-aligned and vertically-centered.

See also
text
PropertiesClass Methods
read alignment
write setAlignment
QLabel::hasSelectedText

This property holds whether there is any text selected. Calling hasSelectedText() returns true if some or all of the text has been selected by the user, otherwise returns false. The textInteractionFlags set on the label need to include either TextSelectableByMouse or TextSelectableByKeyboard.

By default, this property is false.

See also
selectedText()
PropertiesClass Methods
read hasSelectedText
QLabel::indent

This property holds the label's text indent in pixels.

If a label displays text, the indent applies to the left edge if alignment() is Qt::AlignLeft, to the right edge if alignment() is Qt::AlignRight, to the top edge if alignment() is Qt::AlignTop, and to the bottom edge if alignment() is Qt::AlignBottom.

If indent is negative, or if no indent has been set, the label computes the effective indent as follows: If frameWidth() is 0, the effective indent becomes 0. If frameWidth() is greater than 0, the effective indent becomes half the width of the "x" character of the widget's current font().

By default, the indent is -1, meaning that an effective indent is calculating in the manner described above.

See also
alignment, margin, frameWidth(), font()
PropertiesClass Methods
read indent
write setIndent
QLabel::margin

This property holds the width of the margin. The margin is the distance between the innermost pixel of the frame and the outermost pixel of contents.

The default margin is 0.

See also
indent
PropertiesClass Methods
read margin
write setMargin
QLabel::openExternalLinks

Specifies whether QLabel should automatically open links using QDesktopServices::openUrl() instead of emitting the linkActivated() signal. The textInteractionFlags set on the label need to include either LinksAccessibleByMouse or LinksAccessibleByKeyboard.

The default value is false.

See also
textInteractionFlags()
PropertiesClass Methods
read openExternalLinks
write setOpenExternalLinks
QLabel::pixmap

This property holds the label's pixmap.

If no pixmap has been set the property will contain a nullptr. Setting the pixmap clears any previous content. If there is a buddy shortcut it will be disabled.

PropertiesClass Methods
read pixmap
write setPixmap
QLabel::scaledContents

This property holds whether the label will scale its contents to fill all available space. When enabled and the label shows a pixmap, it will scale the pixmap to fill the available space.

This property's default is false.

PropertiesClass Methods
read hasScaledContents
write setScaledContents
QLabel::selectedText

This property holds the selected text. If there is no selected text this property's value is an empty string.

By default, this property contains an empty string.

Note
The textInteractionFlags set on the label need to include either TextSelectableByMouse or TextSelectableByKeyboard.
See also
hasSelectedText()
PropertiesClass Methods
read selectedText
QLabel::text

This property holds the label's text. If no text has been set this will return an empty string. Setting the text clears any previous content. The text will be interpreted either as plain text or as rich text, depending on the text format setting. The default setting is Qt::AutoText. If a buddy has been set the buddy mnemonic key is updated from the new text.

QLabel is well-suited to display small rich text documents, such as small documents that get their document specific settings (font, text color, link color) from the label's palette and font properties. For large documents, use QTextEdit in read-only mode instead. QTextEdit can also provide a scroll bar when necessary.

Note
This method enables mouse tracking if text contains rich text.
See also
setTextFormat(), setBuddy(), alignment
PropertiesClass Methods
read text
write setText
QLabel::textFormat

This property holds the label's text format. Refer to th eQt::TextFormat enum for an explanation of the options. The default format is Qt::AutoText.

See also
text()
PropertiesClass Methods
read textFormat
write setTextFormat
QLabel::textInteractionFlags

Specifies how the label should interact with user input if it displays text. If the flags contain Qt::LinksAccessibleByKeyboard the focus policy is also automatically set to Qt::StrongFocus. If Qt::TextSelectableByKeyboard is set then the focus policy is set to Qt::ClickFocus.

The default value is Qt::LinksAccessibleByMouse.

PropertiesClass Methods
read textInteractionFlags
write setTextInteractionFlags
QLabel::wordWrap

This property holds the label's word-wrapping policy. If this property is true then label text is wrapped where necessary at word-breaks, otherwise it is not wrapped at all.

By default, word wrap is disabled.

See also
text
PropertiesClass Methods
read wordWrap
write setWordWrap