实际的绘制被委托给 drawText 方法。defpaintEvent(self,event):try:qp=QPainter()qp.begin(self)self.drawText(event,qp)self.drawPoints(qp)self.drawSineCurve(qp)qp.end()except:traceback.print_exc()defdrawText(self,event,qp):# 定义绘制文本的笔触和字体。qp.setPen(QColor(168,34,3))# 设置绘制...
painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255), 3)) painter.setBrush(QtGui.QColor(255, 255, 255, 100)) if self.is_macos: start, end = (self.mapFromGlobal(self.start), self.mapFromGlobal(self.end)) else: start, end = self.start, self.end painter.drawRect(QtCore.QRect...
def paintEvent(self, event): # set background_img painter = QPainter(self) painter.drawRect(self.rect()) pixmap = QPixmap("./images/bg.jpg") # 换成自己的图片的相对路径 painter.drawPixmap(self.rect(), pixmap) if __name__=='__main__': app = QApplication(sys.argv) w = MyWidget...
0, 100, 100) def paint(self, painter, option, widget): painter.setBrush(QColor(255, 0, 0)) painter.drawRect(0, 0, 100, 100)然后,将自定义图形
painter.drawRect(QtCore.QRect(self.start, self.end)) return super().paintEvent(event) def mousePressEvent(self, event): self.start = self.end = QtGui.QCursor.pos() self.update() return super().mousePressEvent(event) def mouseMoveEvent(self, event): ...
重写标签的paintEvent方法,在其中使用QPainter绘制矩形: 代码语言:txt 复制 def paintEvent(self, event): painter = QPainter(self) painter.setPen(Qt.red) # 设置画笔颜色为红色 painter.setBrush(QColor(255, 0, 0, 100)) # 设置填充颜色为半透明红色 painter.drawRect(10, 10, 100, 100) # 绘制矩形...
重写标签的paintEvent方法,在其中使用QPainter绘制矩形: 代码语言:txt 复制 def paintEvent(self, event): painter = QPainter(self) painter.setPen(Qt.red) # 设置画笔颜色为红色 painter.setBrush(QColor(255, 0, 0, 100)) # 设置填充颜色为半透明红色 painter.drawRect(10, 10, 100, 100) # 绘制...
painter.end() def drawText(self, event, qp): # 设置笔的颜色 qp.setPen( QColor(168, 34, 3) ) # 设置字体 qp.setFont( QFont('SimSun', 20)) # 画出文本 qp.drawText(event.rect(), Qt.AlignCenter, self.text) if __name__ == "__main__": ...
painter.drawPolygon(polygon)#多边形image = QImage('./python.jpg')#装载图像 QImagerect = QRect(10,600,image.width()/3,image.height()/3) painter.drawImage(rect,image)#画个表盘painter.drawArc(300,100,100,100,0,360*16) pointX =350pointY=150r =50foriinrange(1,13): ...
drawRect(self.rect()) painter.setRenderHint(QtGui.QPainter.Antialiasing) painter.setBrush(QtGui.QBrush(QColor(255, 255, 0, 200))) painter.setPen(QtGui.QPen(QColor(0, 0, 0, 255), 1.0, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) for shape in self.handles.values(): if self.is...