QT画圆 [英] QT drawing a circle

查看:1934
本文介绍了QT画圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



最好的方法是绘制一个圆的半径为r,中心点为x,

谢谢!

解决方案

c> 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 QPointF&中心,qreal rx,qreal ry)



所以你的代码看起来像这样:

  //在MyWidget :: paintEvent()
painter.drawEllipse(QPointF(x,y),radius,radius);

希望有帮助。


I'm learning QT, and had a quick question:

What would be the best way to draw a circle with radius r with the center point at x,y?

Thanks!

解决方案

In a paintEvent use this:

http://doc.qt.io/qt-4.8/qpainter.html#drawEllipse

http://doc.qt.io/qt-4.8/qgraphicsscene.html#addEllipse

In a QGraphicsView/QGraphicsScene use this:

http://doc.qt.io/qt-4.8/qgraphicsellipseitem.html

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 )

So your code would look something like:

// inside MyWidget::paintEvent()
painter.drawEllipse(QPointF(x,y), radius, radius);

Hope that helps.

这篇关于QT画圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆