Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a values around a circle using QPainter class without rotating?

Tags:

draw

qt

qpainter

The question is simple ! I want something like this using QPainter class. enter image description here

i dont want values to be rotated. but using QPainter::rotate method I am getting the values like this(rotated format).

enter image description here

Can someone help me to draw the circle with values like the first image using QPainter

like image 228
Arun Avatar asked Oct 17 '25 01:10

Arun


1 Answers

Here is the simplest code on how I would do it. Assuming I am painting in the paint event of a widget:

#define PI 3.14159265

[..]

void Widget::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);

    QPoint center = rect().center();
    painter.drawEllipse(center, 2, 2);
    const int radius = 100;
    // Draw semicircle with texts on every 30".
    for (double i = .0; i <= 180.0; i += 30.0) {
        QPoint p(center.x() + radius * cos(i * PI / 180.0),
                 center.y() - radius * sin(i * PI / 180.0));
        painter.drawText(p, QString::number(i));
    }
}
like image 185
vahancho Avatar answered Oct 18 '25 22:10

vahancho