def paintEvent(self, event): """Override Qt method""" painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) # Decoration painter.fillPath(self.path_current, QBrush(self.color)) painter.strokePath(self.path_decoration, QPen(self.color_decoration, self.stroke_decoration))
def paintEvent(self, event): """ """ self.build_paths() painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) painter.fillPath(self.round_rect_path, self.color_back) painter.fillPath(self.top_rect_path, self.color_top) painter.strokePath(self.round_rect_path, QPen(Qt.gray, 1))
def paintEvent(self, event) -> None: super(ToolTip, self).paintEvent(event) x = self.rect().x() + self._anchor_width y = self.rect().y() + self._anchor_width w = self.rect().width() - self._anchor_width * 2 h = self.rect().height() - self._anchor_width * 2 # 背景 painter = QPainter(self) path = QPainterPath() path.addRoundedRect(QRectF(x, y, w, h), 4, 4) # 画锚 if self._direction == ToolTip.TOP: x1 = x + w / 2 - self._anchor_width y1 = y + h x2 = x + w / 2 + self._anchor_width y2 = y + h x3 = x + w / 2 y3 = y + h + self._anchor_width path.moveTo(x1, y1) path.lineTo(x2, y2) path.lineTo(x3, y3) elif self._direction == ToolTip.BOTTOM: x1 = x + w / 2 - self._anchor_width y1 = y x2 = x + w / 2 + self._anchor_width y2 = y x3 = x + w / 2 y3 = y - self._anchor_width path.moveTo(x1, y1) path.lineTo(x2, y2) path.lineTo(x3, y3) elif self._direction == ToolTip.RIGHT: x1 = x y1 = y + h / 2 - self._anchor_width x2 = x y2 = y + h / 2 + self._anchor_width x3 = x - self._anchor_width y3 = y + h / 2 path.moveTo(x1, y1) path.lineTo(x2, y2) path.lineTo(x3, y3) elif self._direction == ToolTip.LEFT: x1 = x + w y1 = y + h / 2 - self._anchor_width x2 = x + w y2 = y + h / 2 + self._anchor_width x3 = x + w + self._anchor_width y3 = y + h / 2 path.moveTo(x1, y1) path.lineTo(x2, y2) path.lineTo(x3, y3) painter.fillPath(path, ResourceLoader().qt_color_separator_dark)
def paintEvent(self, event): p = QPainter(self) p.fillRect(QRect(0, 0, self.width(), self.height()), Qt.gray) p.setWorldTransform(self.m_window_matrix.toTransform()) mvp = QMatrix4x4(self.m_projection * self.m_view * self.m_model) p.setTransform(mvp.toTransform(), True) p.fillPath(painterPathForTriangle(), self.m_brush) self.m_model.rotate(1, 0, 1, 0)
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHints(QPainter.Antialiasing) painter.setPen(Qt.NoPen) if self.hover: painter.setBrush( QColor(self.back_color.red() + 30, self.back_color.green() + 30, self.back_color.blue() + 30)) self.lineEdit.set_back_color( QColor(self.back_color.red() + 30, self.back_color.green() + 30, self.back_color.blue() + 30)) else: painter.setBrush(self.back_color) self.lineEdit.set_back_color(self.back_color) painter.drawRoundedRect(QRect(0, 0, self.width(), self.height()), self.border_radius, self.border_radius) pen = QPen(self.down_arrow_color, self.drop_thick, Qt.SolidLine) painter.setPen(pen) self.down_arrow_poly = QPolygon() x1 = QPoint(self.label_width + float(self.height() / 3), float(self.height() * 0.6)) x2 = QPoint( self.label_width + float(self.height() / 3) + float(self.height() * self.rate / 2), float(self.height() * 0.75)) x3 = QPoint(self.width() - float(self.height() / 3), float(self.height() * 0.6)) self.down_arrow_poly << x1 << x2 << x3 check_path = QPainterPath() check_path.moveTo(x1) check_path.lineTo(x2) check_path.lineTo(x3) check_path.lineTo(x1) painter.drawPath(check_path) if self.down_arrow_color == self.arrow_activate_color: painter.fillPath(check_path, QBrush(self.down_arrow_color)) else: if self.hover: painter.fillPath( check_path, QColor(self.back_color.red() + 30, self.back_color.green() + 30, self.back_color.blue() + 30)) else: painter.fillPath(check_path, QBrush(self.back_color)) pen = QPen(self.up_arrow_color, self.drop_thick, Qt.SolidLine) painter.setPen(pen) x1 = QPoint(self.label_width + float(self.height() / 3), float(self.height() * 0.4)) x2 = QPoint( self.label_width + float(self.height() / 3) + float(self.height() * self.rate / 2), float(self.height() * 0.25)) x3 = QPoint(self.width() - float(self.height() / 3), float(self.height() * 0.4)) self.up_arrow_poly = QPolygon() self.up_arrow_poly << x1 << x2 << x3 check_path = QPainterPath() check_path.moveTo(x1) check_path.lineTo(x2) check_path.lineTo(x3) check_path.lineTo(x1) painter.drawPath(check_path) if self.up_arrow_color == self.arrow_activate_color: painter.fillPath(check_path, QBrush(self.up_arrow_color)) else: if self.hover: painter.fillPath( check_path, QColor(self.back_color.red() + 30, self.back_color.green() + 30, self.back_color.blue() + 30)) else: painter.fillPath(check_path, QBrush(self.back_color))