C++ QT画圆
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17375808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
QT drawing a circle
提问by Nathan
I'm learning QT, and had a quick question:
我正在学习 QT,并有一个简单的问题:
What would be the best way to draw a circle with radius r with the center point at x,y?
以 x,y 为中心点绘制半径为 r 的圆的最佳方法是什么?
Thanks!
谢谢!
回答by phyatt
In a paintEvent
use this:
在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
use this:
在QGraphicsView
/ 中QGraphicsScene
使用:
http://doc.qt.io/qt-4.8/qgraphicsellipseitem.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
The last link listed, is an overloaded method that allows you to enter the center point with the two radii specified.
列出的最后一个链接是一种重载方法,允许您输入具有指定两个半径的中心点。
void QPainter::drawEllipse ( const QPointF & center, qreal rx, qreal ry )
void QPainter::drawEllipse ( const QPointF & center, qreal rx, qreal ry )
So your code would look something like:
所以你的代码看起来像:
// inside MyWidget::paintEvent()
painter.drawEllipse(QPointF(x,y), radius, radius);
Hope that helps.
希望有帮助。