def paintEvent(self, a0: QPaintEvent) -> None: super().paintEvent(a0) painter = QPainter(self) painter.save() painter.setRenderHint(QPainter.Antialiasing) rect = QRectF(self.margin, self.margin, self.width() - self.margin * 2, self.height() - 2 * self.margin) painter.setBrush(Qt.white) painter.setPen(Qt.white) painter.drawEllipse(rect) painter.restore() painter.save() painter.setRenderHint(QPainter.Antialiasing) pen = QPen() pen.setWidth(2) painter.setPen(pen) mid_point = QPointF(a0.rect().width() / 2, a0.rect().height() / 2) radius = min(a0.rect().height(), a0.rect().width()) / 3 rays_num = 10 for i in range(rays_num): point = QPointF( math.sin(math.pi / (rays_num / 2) * i) * radius, math.cos(math.pi / (rays_num / 2) * i) * radius) painter.drawLine(mid_point + (point * 0.4), mid_point + point) painter.restore()
def paintEvent(self, event: QPaintEvent): rect = event.rect() painter = QPainter(self) color = painter.pen().color() lock = qta.icon("fa5s.lock", color=color) if self.isChecked() else qta.icon( "fa5s.lock-open", color=color) lock.paint(painter, rect)
def paintEvent(self, event: QPaintEvent) -> None: """Using a QPainter under 'self', so just change QPen or QBrush before painting. """ if not self.__grab_mode: self.painter.begin(self) self.painter.fillRect(event.rect(), QBrush(Qt.white)) # Translation self.painter.translate(self.ox, self.oy) # Background if not self.background.isNull(): rect = self.background.rect() self.painter.setOpacity(self.background_opacity) self.painter.drawImage( QRectF( self.background_offset * self.zoom, QSizeF(rect.width(), rect.height()) * self.background_scale * self.zoom), self.background, QRectF(rect)) self.painter.setOpacity(1) # Show frame pen = QPen(Qt.blue) pen.setWidth(1) self.painter.setPen(pen) self.painter.setFont(QFont("Arial", self.font_size)) # Draw origin lines if self.show_ticks not in {_TickMark.SHOW, _TickMark.SHOW_NUM}: return pen.setColor(Qt.gray) self.painter.setPen(pen) x_l = -self.ox x_r = self.width() - self.ox self.painter.drawLine(QPointF(x_l, 0), QPointF(x_r, 0)) y_t = self.height() - self.oy y_b = -self.oy self.painter.drawLine(QPointF(0, y_b), QPointF(0, y_t)) def indexing(v: float) -> int: """Draw tick.""" return int(v / self.zoom - v / self.zoom % 5) # Draw tick for x in range(indexing(x_l), indexing(x_r) + 1, 5): if x == 0: continue is_ten = x % 10 == 0 end = QPointF(x * self.zoom, -10 if is_ten else -5) self.painter.drawLine(QPointF(x, 0) * self.zoom, end) if self.show_ticks == _TickMark.SHOW_NUM and is_ten: self.painter.drawText(end + QPointF(0, 3), f"{x}") for y in range(indexing(y_b), indexing(y_t) + 1, 5): if y == 0: continue is_ten = y % 10 == 0 end = QPointF(10 if is_ten else 5, y * self.zoom) self.painter.drawLine(QPointF(0, y) * self.zoom, end) if self.show_ticks == _TickMark.SHOW_NUM and is_ten: self.painter.drawText(end + QPointF(3, 0), f"{-y}")
def paintEvent(self, event: QPaintEvent): rect = event.rect() painter = QPainter(self) painter.save() if self.isChecked(): lock = lock_close else: lock = lock_open painter.setFont(QFont("Symbola")) painter.drawText(rect.bottomLeft() + QPoint(0, -2), lock) painter.restore()
def paintEvent(self, event: QPaintEvent): painter = QPainter(self) painter.fillRect(event.rect(), self._qcolor)
def paintEvent(self, event: QPaintEvent): name = self.choose.currentText() if self.widgets_dict[name].has_elements() and event.rect().top() == 0 and event.rect().left() == 0: painter = QPainter(self) painter.drawRect(event.rect())
def test_typhonbase_repaint_smoke(qtbot): tp = TyphonBase() qtbot.addWidget(tp) pe = QPaintEvent(QRect(1, 2, 3, 4)) tp.paintEvent(pe)
def paintEvent(self, event: QPaintEvent): rect = event.rect() painter = QPainter(self) if self.parent().image is not None: parent: "ColorSelector" = self.parent() painter.drawImage(rect, parent.image)