painter.drawEllipse(80, 10, 50, 30) # 绘制一个椭圆 painter.drawRect(180, 10, 50, 30) # 绘制一个矩形 painter.drawLine(80, 70, 200, 70) # 绘制直线 painter.drawText(50, 100, "岂能尽如人意,但求无愧我心。") if __name__ == "__main__": import sys app = QApplication(sys.ar...
paintEvent()函数的实现,一般是先创建一个QPainter对象,然后调用QPainter的绘制函数,最后销毁QPainter对象。 defpaintEvent(self, event): painter = QPainter(self) painter.drawPixmap(self.rect(), self.pixmap) painter.end() QPainter提供了一对函数begin()和end()来管理绘制的生命周期,这两个函数是成对出现...
drawPoint(self.Point_list[i*2],self.Point_list[i*2+1]) print("DrawPoint") elif self.Draw == "Elipse": painter.drawEllipse(self.Elipse_list[0],self.Elipse_list[1],self.Elipse_list[2],self.Elipse_list[3]) print("DrawElipse") elif self.Draw == "Rectangle": painter.drawRect(self...
painter.drawEllipse(150,150,100,100) 画矩形: 代码语言:javascript 复制 painter.drawRect(100,100,100,150) 画文本: 代码语言:javascript 复制 painter.drawText(120,120,"文字") 画多边形: 代码语言:javascript 复制 polygon=QPolygon()polygon.setPoints(5,100,100,140,130,160,160,170,140,140,178)pain...
PyQt5绘制图形的方法可以通过使用QPainter对象来实现。以下是一些常用的绘图方法:1. 绘制线段:使用QPainter的drawLine()方法绘制直线。可以指定线段的起始点和终点坐标。...
qp = QPainter() qp.begin(self) self.drawText(event, qp) qp.end() def drawText(self, event, qp): qp.setPen(QColor(168, 34, 3)) qp.setFont(QFont('Decorative', 10)) qp.drawText(event.rect(), Qt.AlignCenter, self.text) ...
super(Drawall,self).__init__() self.setWindowTitle("绘制各种图形") self.resize(300,600) def paintEvent(self,event): painter=QPainter(self) #先定义画布 painter.begin(self) #初始化画布 painter.setPen(Qt.blue) #绘制弧线 rect=QRect(0,10,100,100) #确定画出圆弧的正方形区域(x左上角横坐...
painter.setPen(Qt.blue) painter.setFont(QFont("Arial", 30)) painter.drawText(rect(), Qt.AlignCenter, "OpenCV学堂") 上述代码首先获取画笔,然后设置颜色与字体,最后绘制文本。通过用户创建Painter实例的方式绘制,绘制结束之后需要显式销毁,通过系统的painter绘制则无需这样,对比如下:用户创建绘制 ...
CustomGraphicsItem(QGraphicsItem): def __init__(self): super().__init__() def boundingRect(self): return QRectF(0, 0, 100, 100) def paint(self, painter, option, widget): painter.setBrush(QColor(255, 0, 0)) painter.drawRect(0, 0, 100, 100)然后,将自定义...
painter = QPainter(self) pen = QPen(Qt.black, 2, Qt.SolidLine) painter.setPen(pen) # 绘制一个矩形 painter.drawRect(10, 10, 100, 50) # 绘制一条直线 painter.drawLine(10, 70, 100, 70) # 绘制一个椭圆 painter.drawEllipse(120, 10, 60, 30) # 绘制文本 painter.drawText(190, 10, ...