def paintEvent(self, event): QDialog.paintEvent(self, event) if not self.line.isNull(): painter = QPainter(self) pen = QPen(Qt.GlobalColor.red, 3) painter.setPen(pen) painter.drawLine(self.line)
def paintEvent(self, event): qp = QPainter() qp.begin(self) qp.setBrush(FILLBRUSH) qp.drawRect(self.rect()) # Show question if self.parent().alex: anheight = ANSWERHEIGHT * self.size().height() qp.drawLine( 0, (1 - ANSWERHEIGHT) * self.size().height(), self.size().width(), (1 - ANSWERHEIGHT) * self.size().height(), )
def mouseMoveEvent(self, event): if self.xCache == None: self.xCache = event.position().x() self.yCache = event.position().y() else: painter = QPainter(self.canvas) pen = painter.pen() pen.setWidth(self.strokeWidth) pen.setColor(QColor(*self.color)) pen.setStyle(self.strokeStyle) painter.setPen(pen) painter.drawLine(self.xCache, self.yCache, event.position().x(), event.position().y()) painter.end() self.setPixmap(self.canvas) self.xCache = event.position().x() self.yCache = event.position().y()
def draw_arrow_p(start: Tuple[int, int], end: Tuple[int, int], arrow_head1: Tuple[int, int], arrow_head2: Tuple[int, int], painter: QPainter, filled_arrow_head: bool = False): # painter.setPen(color) painter.drawLine(*start, *end) if not filled_arrow_head: painter.drawLine(*end, *arrow_head1) painter.drawLine(*end, *arrow_head2) else: # brush0 = painter.pen().brush() # painter.setBrush(painter.pen().color()) path = QPainterPath() path.moveTo(*end) path.lineTo(*arrow_head1) path.lineTo(*arrow_head2) path.lineTo(*end) painter.drawPath(path)