I think this is what you want
{
protected:
{
const double radius = qSqrt(qPow(width()/2.0, 2) + qPow(height()/2.0, 2));
const int startAngle = qAtan((width()/2.0)/radius) * 180 / M_PI * 16;
const int spanAngle = (90 - startAngle) * 2 * 16;
const QRect rect
= event
->rect
().
adjusted(-(radius
-width
()/2.0), height
()-radius,
(radius
-width
()/2.0), radius
);
painter.drawArc(rect, startAngle, spanAngle);
}
};
int main(int argc, char *argv[])
{
ArcWidget widget;
widget.show();
return app.exec();
}
class ArcWidget : public QWidget
{
protected:
void paintEvent(QPaintEvent * event) override
{
QPainter painter(this);
const double radius = qSqrt(qPow(width()/2.0, 2) + qPow(height()/2.0, 2));
const int startAngle = qAtan((width()/2.0)/radius) * 180 / M_PI * 16;
const int spanAngle = (90 - startAngle) * 2 * 16;
const QRect rect = event->rect().adjusted(-(radius-width()/2.0), height()-radius, (radius-width()/2.0), radius);
painter.drawArc(rect, startAngle, spanAngle);
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ArcWidget widget;
widget.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks