QPainter画不填充的圆
时间: 2024-01-02 19:02:50 浏览: 57
可以使用QPainter的drawEllipse方法来画不填充的圆,代码如下:
```python
from PyQt5.QtGui import QPainter, QPen
from PyQt5.QtCore import Qt, QPoint
from PyQt5.QtWidgets import QWidget, QApplication
import sys
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('Example')
def paintEvent(self, event):
qp = QPainter()
qp.begin(self)
self.drawCircle(qp)
qp.end()
def drawCircle(self, qp):
pen = QPen(Qt.black, 2, Qt.SolidLine)
qp.setPen(pen)
center = QPoint(175, 150)
radius = 100
qp.drawEllipse(center, radius, radius)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())
```
在这个例子中,我们创建了一个继承自QWidget的Example类,并在其中实现了paintEvent方法和drawCircle方法。
在paintEvent方法中,我们创建了一个QPainter对象,并在其中调用drawCircle方法。
在drawCircle方法中,我们设置了一个黑色的画笔,并使用drawEllipse方法画了一个不填充的圆。其中,center是圆心坐标,radius是半径。
最后,我们创建了一个QApplication对象,并将Example对象显示出来。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)