我正在学习 QT,有一个简单的问题:
画一个半径为 r、中心点为 x,y 的圆的最佳方法是什么?
Thanks!
In a paintEvent
用这个:
http://doc.qt.io/qt-4.8/qpainter.html#drawEllipse http://doc.qt.io/qt-4.8/qpainter.html#drawEllipse
http://doc.qt.io/qt-4.8/qgraphicsscene.html#addEllipse http://doc.qt.io/qt-4.8/qgraphicsscene.html#addEllipse
In a QGraphicsView
/QGraphicsScene
用这个:
http://doc.qt.io/qt-4.8/qgraphicsellipsitem.html http://doc.qt.io/qt-4.8/qgraphicsellipseitem.html
http://doc.qt.io/qt-4.8/qpainter.html#drawEllipse 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);
希望有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)