QT绘制圆形

8

我正在学习QT,有一个快速问题:

如何以x,y为圆心,半径为r绘制一个圆?

谢谢!


请求教程只是附带说明,主要问题是关于圆形的。 - Nathan
改为只询问圆形。 - Nathan
1
哦,就这个而言:仅仅是画一个圆,它看起来非常像另一个问题的重复。 - Jerry Coffin
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);

希望能有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接