Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QT drawing a circle [duplicate]

Tags:

c++

qt

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!

like image 804
Nathan Avatar asked Jun 29 '13 01:06

Nathan


People also ask

How do you draw a circle in Qt?

So your code would look something like: // inside MyWidget::paintEvent() painter. drawEllipse(QPointF(x,y), radius, radius); Hope that helps.

How do you make a round button in Qt?

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 .


1 Answers

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.

like image 58
phyatt Avatar answered Sep 16 '22 12:09

phyatt