-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgltextlabel.cpp
More file actions
38 lines (34 loc) · 1.08 KB
/
Copy pathgltextlabel.cpp
File metadata and controls
38 lines (34 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "gltextlabel.h"
GlTextLabel::GlTextLabel(GlObject* parent) : GlObject(parent)
{
borderColor = QColor(66, 74, 90);
gradientColorAt0 = QColor(40,40,40);
gradientColorAt1 = QColor(96,112,144);
border = 1;
borderRadius = 10;
fontColor = QColor(255,255,255,128);
fontSize = 20;
}
void GlTextLabel::draw(QPainter *p)
{
QLinearGradient gradient(getX(), getY() + getHeight()/2,
getX() + getWidth(), getY() + getHeight()/2);
gradient.setColorAt(0, gradientColorAt0);
gradient.setColorAt(1, gradientColorAt1);
p->setBrush(QBrush(gradient));
QPainterPath pa;
pa.addRoundedRect(geometry(), borderRadius, borderRadius);
pen.setWidth(border); //Strichbreite
pen.setColor(borderColor); //Strichfarbe
p->setPen(pen);
p->drawPath(pa);
QFont font = p->font();
font.setPixelSize(fontSize);
font.setBold(true);
pen.setColor(fontColor);
p->setFont(font);
p->setPen(pen);
QRect rect = geometry();
rect.setX(rect.x() + 10);
p->drawText(rect, text, QTextOption(Qt::AlignVCenter));
}