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!
So your code would look something like: // inside MyWidget::paintEvent() painter. drawEllipse(QPointF(x,y), radius, radius); Hope that helps.
To create a completely circular button (the default), use a value that is equal to half of the width or height of the button, and make the button's width and height identical. To reset this property back to the default value, set its value to undefined .
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.
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