QT画一个圆圈

Nat*_*han 7 c++ qt

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

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

谢谢!

phy*_*att 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);
Run Code Online (Sandbox Code Playgroud)

希望有所帮助.