8

我正在学习 QT,并且有一个简单的问题:

以 x,y 为中心点绘制半径为 r 的圆的最佳方法是什么?

谢谢!

4

1 回答 1

14

paintEvent使用中:

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

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

QGraphicsView/中QGraphicsScene使用:

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

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

列出的最后一个链接是一种重载方法,允许您输入指定的两个半径的中心点。

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

所以你的代码看起来像:

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

希望有帮助。

于 2013-06-29T02:00:10.867 回答