CANdevStudio
Development tool for CAN bus simulation
Loading...
Searching...
No Matches
iconlabel.h
Go to the documentation of this file.
1#ifndef __ICONLABEL_H
2#define __ICONLABEL_H
3
4#include <QLabel>
5#include <QLayoutItem>
6#include <QPainter>
7#include <QVariant>
8
9class IconLabel : public QLabel {
10public:
11 IconLabel(const QString& name, const QColor& headerColor, const QColor& bgColor)
12 {
13 QPixmap pix(_width, _height);
14 pix.fill(Qt::transparent);
15 QPainter painter(&pix);
16
17 painter.setPen(Qt::NoPen);
18
19 painter.setRenderHint(QPainter::Antialiasing);
20
21 painter.setBrush(QBrush(bgColor));
22 QRectF boundary(0, 0, pix.width(), pix.height());
23 painter.drawRoundedRect(boundary, _radius, _radius);
24 painter.setBrush(QBrush(headerColor));
25
26 QRectF boundary2(0, 0, pix.width(), _labelHeight);
27 painter.drawRoundedRect(boundary2, _radius, _radius);
28
29 QRectF boundary3(0, _labelHeight / 2, pix.width(), _labelHeight / 2);
30 painter.drawRect(boundary3);
31
32 painter.setPen({ Qt::white, 1 });
33 QFont font({ "Arial", 8 });
34 font.setBold(true);
35 painter.setFont(font);
36 painter.drawText(6, 15, name);
37
38 setMinimumSize(_width, _height);
39 setMaximumSize(_width, _height);
40 setObjectName(name);
41 setPixmap(pix);
42
43 setProperty("type", "IconLabel");
44 }
45
46 QSize minimumSizeHint() const override
47 {
48 return { _width, _height };
49 }
50
51private:
52 const int _width = 140;
53 const int _height = 48;
54 const int _labelHeight = 22;
55 const double _radius = 3.0;
56};
57
58#endif /* !__ICONLABEL_H */
Definition iconlabel.h:9
QSize minimumSizeHint() const override
Definition iconlabel.h:46
IconLabel(const QString &name, const QColor &headerColor, const QColor &bgColor)
Definition iconlabel.h:11