QT画一个圆圈

时间:2013-06-29 01:28:57

标签: c++ qt

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

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

谢谢!

1 个答案:

答案 0 :(得分:13)

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);

希望有所帮助。

相关问题