1 Use QPainterPath and QPainterPath::arcTo functions
void QPainterPath::arcTo(const QRectF & rectangle, qreal startAngle, qreal sweepLength)
Create an arc that occupies the specified rectangle to specify the startAngle angle (0-360). Start rotating sweepLength degrees.
When sweepLength is a positive number, it rotates counterclockwise, and when it is a negative number, it rotates clockwise.
class Example(QFrame):
def __init__(self):
super().__init__()
self.setFixedSize(600,800)
self.arcRadius=45
self.startPos=(100,100)
def paintEvent(self,event):
painter = QPainter(self)
painter.setBrush(Qt.green)
painter.setRenderHint(QPainter.Antialiasing)
#绘制第一段
path1 = QPainterPath()
path1.moveTo(*self.startPos)
path1.arcTo(QRectF(self.startPos[0],self.startPos[1]-self.arcRadius,self.arcRadius*2,self.arcRadius*2),180,-90)
print(path1.currentPosition())
path1.lineTo(145+100,55)
path1.lineTo(self.startPos[0],self.startPos[1])
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
ex.show()
app.exit(app.exec_())