KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
label.h
1#ifndef LABEL_H
2#define LABEL_H
3
4#include <QLabel>
5#include <Kanoop/gui/libkanoopgui.h>
6
7/**
8 * @brief QLabel subclass with font size and color Q_PROPERTYs.
9 *
10 * Label exposes foregroundColor and backgroundColor as Qt properties,
11 * allowing them to be set from Qt Designer or stylesheets. It also
12 * provides setFontPointSize() and setFontPixelSize() for quick font-size
13 * changes without manual QFont manipulation.
14 */
15class LIBKANOOPGUI_EXPORT Label : public QLabel
16{
17 Q_OBJECT
18
19 /** @brief Foreground (text) color of the label. */
20 Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor) // clazy:exclude=qproperty-without-notify
21 /** @brief Background color of the label. */
22 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) // clazy:exclude=qproperty-without-notify
23public:
24 /**
25 * @brief Construct with optional parent and window flags.
26 * @param parent Optional QWidget parent
27 * @param f Optional window flags
28 */
29 explicit Label(QWidget *parent = nullptr, Qt::WindowFlags f=Qt::WindowFlags());
30
31 /**
32 * @brief Construct with initial text, optional parent and window flags.
33 * @param text Initial label text
34 * @param parent Optional QWidget parent
35 * @param f Optional window flags
36 */
37 explicit Label(const QString &text, QWidget *parent = nullptr, Qt::WindowFlags f=Qt::WindowFlags());
38
39 /**
40 * @brief Set the font size in points.
41 * @param size Point size
42 */
43 void setFontPointSize(int size);
44
45 /**
46 * @brief Set the font size in pixels.
47 * @param size Pixel size
48 */
49 void setFontPixelSize(int size);
50
51 /**
52 * @brief Return the current foreground color.
53 * @return Foreground (text) color
54 */
55 QColor foregroundColor() const { return _foregroundColor; }
56
57 /**
58 * @brief Return the current background color.
59 * @return Background color
60 */
61 QColor backgroundColor() const { return _backgroundColor; }
62
63public slots:
64 /**
65 * @brief Set the foreground (text) color and repaint.
66 * @param color New foreground color
67 */
68 void setForegroundColor(const QColor& color);
69
70 /**
71 * @brief Set the background color and repaint.
72 * @param color New background color
73 */
74 void setBackgroundColor(const QColor& color);
75
76public:
77 /** @brief Reset the foreground color to the palette default. */
79 /** @brief Reset the background color to the palette default. */
81
82protected:
83 /** @brief Rebuild and apply the stylesheet from current color properties. */
84 virtual void applyStylesheet();
85
86private:
87 void commonInit();
88
89 QColor _backgroundColor;
90 QColor _foregroundColor;
91 bool _backgroundExplicitlySet = false;
92 bool _foregroundExplicitlySet = false;
93};
94
95#endif // LABEL_H
QLabel subclass with font size and color Q_PROPERTYs.
Definition label.h:16
void setDefaultBackgroundColor()
Reset the background color to the palette default.
void setBackgroundColor(const QColor &color)
Set the background color and repaint.
void setDefaultForegroundColor()
Reset the foreground color to the palette default.
virtual void applyStylesheet()
Rebuild and apply the stylesheet from current color properties.
QColor backgroundColor() const
Return the current background color.
Definition label.h:61
void setForegroundColor(const QColor &color)
Set the foreground (text) color and repaint.