25 static const QPoint needle[4] = {
32 auto text = tr((to_string(
value) +
" m/s").c_str());
34 QColor needleColor(0,0,0);
37 auto time = QTime::currentTime();
39 QPainter painter(
this);
40 painter.setRenderHint(QPainter::Antialiasing);
41 painter.translate(width() / 2, height()-25);
42 painter.scale(side / 200.0, side / 200.0);
44 painter.setPen(Qt::NoPen);
45 painter.setBrush(needleColor);
48 painter.rotate( (
value * (180./6.)) - 90.);
50 painter.drawConvexPolygon(needle, 4);
53 painter.setPen(Qt::black);
54 auto text_width = painter.fontMetrics().width(text);
55 painter.drawText(QRectF(-text_width/2., -40, 100, 20), text);
57 for (
int j = 0; j < 30; ++j) {
59 painter.setPen(QColor(255 - ((255. / 30.) * j), (255. / 30.) * j, 0));
60 painter.drawLine(92, 0, 96, 0);
62 painter.setPen(QColor(0,0,0));
63 painter.drawLine(84, 0, 96, 0);
Speedometer(QWidget *parent=0)
void paintEvent(QPaintEvent *event) override
void setValue(float value)