8

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!

Nathan
  • 73,987
  • 14
  • 40
  • 69

1 Answers1

14

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.

Amit Tomar
  • 4,800
  • 6
  • 50
  • 83
phyatt
  • 18,472
  • 5
  • 61
  • 80