KanoopGuiQt 1.3.0
Qt GUI utility library
Loading...
Searching...
No Matches
iconlabel.h
1#ifndef ICONLABEL_H
2#define ICONLABEL_H
3
4#include <QWidget>
5#include <Kanoop/gui/libkanoopgui.h>
6
7class QLabel;
8
9/**
10 * @brief Composite widget showing a text label alongside an icon.
11 *
12 * IconLabel places a QLabel for text and a QLabel for a QIcon side by side.
13 * The icon alignment within the layout can be controlled independently of the
14 * text alignment.
15 */
16class LIBKANOOPGUI_EXPORT IconLabel : public QWidget
17{
18 Q_OBJECT
19public:
20 /**
21 * @brief Construct an empty IconLabel.
22 * @param parent Optional QWidget parent
23 */
24 explicit IconLabel(QWidget *parent = nullptr);
25
26 /**
27 * @brief Construct with text only.
28 * @param text Initial label text
29 * @param parent Optional QWidget parent
30 */
31 explicit IconLabel(const QString& text, QWidget *parent = nullptr);
32
33 /**
34 * @brief Construct with text and an icon.
35 * @param text Initial label text
36 * @param icon Icon to display alongside the text
37 * @param parent Optional QWidget parent
38 */
39 explicit IconLabel(const QString& text, const QIcon& icon, QWidget *parent = nullptr);
40
41 /**
42 * @brief Return the current label text.
43 * @return Text string
44 */
45 QString text() const;
46
47 /**
48 * @brief Set the label text.
49 * @param text New text string
50 */
51 void setText(const QString& text);
52
53 /**
54 * @brief Return the current icon.
55 * @return Icon displayed in the widget
56 */
57 QIcon icon() const;
58
59 /**
60 * @brief Set the icon.
61 * @param icon New icon to display
62 */
63 void setIcon(const QIcon& icon);
64
65 /**
66 * @brief Set the alignment of the icon within the layout.
67 * @param alignment Qt alignment flags
68 */
69 void setIconAlignment(Qt::Alignment alignment);
70
71private:
72 void createLayout(const QString& text, const QIcon& icon);
73
74 QLabel* _label = nullptr;
75 QLabel* _iconLabel = nullptr;
76
77signals:
78
79private slots:
80
81};
82
83#endif // ICONLABEL_H
Composite widget showing a text label alongside an icon.
Definition iconlabel.h:17
void setIcon(const QIcon &icon)
Set the icon.
IconLabel(const QString &text, const QIcon &icon, QWidget *parent=nullptr)
Construct with text and an icon.
void setIconAlignment(Qt::Alignment alignment)
Set the alignment of the icon within the layout.
IconLabel(const QString &text, QWidget *parent=nullptr)
Construct with text only.
IconLabel(QWidget *parent=nullptr)
Construct an empty IconLabel.
QIcon icon() const
Return the current icon.
void setText(const QString &text)
Set the label text.
QString text() const
Return the current label text.