QT drawing a circle

c++, qt

Solution

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 the center point with the two radii specified.

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

So your code would look something like:

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

Hope that helps.

Problem

I'm learning QT, and had a quick question: What would be the best way to draw a circle with radius r with the center point at x,y? Thanks!

Original source

Related problems