QGraphicsView画圆弧
时间: 2023-09-15 10:16:38 浏览: 99
可以使用QPainter在QGraphicsView上画圆弧。以下是一个简单的示例代码:
```python
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene
from PyQt5.QtGui import QPainter, QPen, QColor
from PyQt5.QtCore import Qt, QRectF
class MyGraphicsView(QGraphicsView):
def __init__(self, parent=None):
super().__init__(parent)
self.scene = QGraphicsScene(self)
self.setScene(self.scene)
self.drawArc()
def drawArc(self):
pen = QPen(QColor(255, 0, 0))
pen.setWidth(2)
rect = QRectF(50, 50, 200, 200)
startAngle = 30 * 16
spanAngle = 120 * 16
painter = QPainter()
painter.begin(self.scene)
painter.setRenderHint(QPainter.Antialiasing)
painter.setPen(pen)
painter.drawArc(rect, startAngle, spanAngle)
painter.end()
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
view = MyGraphicsView()
view.show()
sys.exit(app.exec_())
```
这个示例代码创建了一个QGraphicsView窗口,并在其中画了一个红色的圆弧。你可以根据需要调整圆弧的位置、大小、起始角度和跨越角度。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)