QT draws a circle

I am learning QT and am asking a quick question:

What would be the best way to draw a circle with radius r with a center point at x, y?

Thanks!

+6
source share
1 answer

In a paintEvent use this:

http://doc.qt.io/qt-4.8/qpainter.html#drawEllipse

http://doc.qt.io/qt-4.8/qgraphicsscene.html#addEllipse

In a QGraphicsView / QGraphicsScene use this:

http://doc.qt.io/qt-4.8/qgraphicsellipseitem.html

http://doc.qt.io/qt-4.8/qpainter.html#drawEllipse

The last link listed is an overloaded method that allows you to enter a center point with the indicated two indicated radii.

void QPainter::drawEllipse ( const QPointF & center, qreal rx, qreal ry )

So your code will look something like this:

 // inside MyWidget::paintEvent() painter.drawEllipse(QPointF(x,y), radius, radius); 

Hope this helps.

+11
source

Source: https://habr.com/ru/post/948359/


All Articles