The question is simple ! I want something like this using QPainter
class.
i dont want values to be rotated. but using QPainter::rotate
method I am getting the values like this(rotated format).
Can someone help me to draw the circle with values like the first image using QPainter
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));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With