凌的博客

您现在的位置是:首页  > 学无止境 > python

python

PyQt5 QPainter绘制基础图形

2019-10-05python0
界面刷新为:

QPainter基础流程为:

 def paintEvent(self, QPaintEvent):
            painter = QPainter(self)
            painter.setPen(QColor(166,66,250))          
            painter.begin(self)
            painter.draw-----#绘制函数
            painter.end()
#界面刷新为:
self.update()
#画笔设置:
painter.setPen(QColor(166,66,250))  
#画点:
painter.drawPoint(100,100)
#画线:
painter.drawLine(100,100,200,200)
#画圆:
painter.drawEllipse(150,150,100,100)
#画矩形:
painter.drawRect(100,100,100,150)
#画文本:
painter.drawText(120,120,"文字")
#画多边形:
polygon = QPolygon()
polygon.setPoints(5,100,100,140,130,160,160,170,140,140,178)
painter.drawPolygon(polygon)
#画扇形:
painter.drawPie(100,100,200,200,0*16,120*16)
#画弧形:
painter.drawArc(100,100,200,200,30*16,120*16)
#画路径:
path = QPainterPath()
path.addRect(100,100,100,100)
path.addEllipse(150,150,60,80)
painter.setBrush(Qt.blue)
#path.setFillRule(Qt.WindingFill) #非零填充规则
path.setFillRule(Qt.OddEvenFill) #奇偶填充规则
painter.drawPath(path)


如果本文对您有所帮助,请支持下本站哦!!!^_^

文章评论

0条评论