def paintEvent(self, QPaintEvent): self.updatePosition() painter = QPainter(self) painter.fillRect(self.rect(), Qt.transparent) painter.setRenderHint(QPainter.Antialiasing, True) if self._currentCounter >= self._numberOfLines: self._currentCounter = 0 painter.setPen(Qt.NoPen) for i in range(self._numberOfLines): painter.save() painter.translate(self._innerRadius + self._lineLength, self._innerRadius + self._lineLength) rotateAngle = float(360 * i) / float(self._numberOfLines) painter.rotate(rotateAngle) painter.translate(self._innerRadius, 0) distance = self.lineCountDistanceFromPrimary( i, self._currentCounter, self._numberOfLines) color = self.currentLineColor(distance, self._numberOfLines, self._trailFadePercentage, self._minimumTrailOpacity, self._color) painter.setBrush(color) painter.drawRoundedRect( QRectF(0, -self._lineWidth / 2, self._lineLength, self._lineWidth), self._roundness, self._roundness, Qt.RelativeSize) painter.restore()
def draw_node_rect(painter: QPainter, geom: NodeGeometry, model: NodeDataModel, graphics_object: NodeGraphicsObject, node_style: NodeStyle): """ Draw node rect Parameters ---------- painter : QPainter geom : NodeGeometry model : NodeDataModel graphics_object : NodeGraphicsObject node_style : NodeStyle """ color = (node_style.selected_boundary_color if graphics_object.isSelected() else node_style.normal_boundary_color) p = QPen(color, (node_style.hovered_pen_width if geom.hovered else node_style.pen_width)) painter.setPen(p) gradient = QLinearGradient(QPointF(0.0, 0.0), QPointF(2.0, geom.height)) for at_, color in node_style.gradient_colors: gradient.setColorAt(at_, color) painter.setBrush(gradient) diam = node_style.connection_point_diameter boundary = QRectF(-diam, -diam, 2.0 * diam + geom.width, 2.0 * diam + geom.height) radius = 3.0 painter.drawRoundedRect(boundary, radius, radius)
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHints(QPainter.Antialiasing) side = min(self.width(), self.height()) painter.scale(side / 32.0, side / 32.0) painter.setPen(Qt.NoPen) if not self.is_pressed: painter.setBrush(self.back_color) else: painter.setBrush( QColor(self.back_color.red() + 30, self.back_color.green() + 30, self.back_color.blue() + 30)) painter.drawRoundedRect(QRect(0, 0, 32, 32), 8, 8) if self.is_checked: check_path = QPainterPath() check_path.moveTo(self.x1) check_path.lineTo(self.x2) check_path.lineTo(self.x3) pen = QPen(self.check_color, self.check_thick, Qt.SolidLine) painter.setPen(pen) painter.drawPath(check_path)
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHints(QPainter.Antialiasing) if self.label_width <= 0: return 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)) else: painter.setBrush(self.back_color) painter.drawRoundedRect(QRect(0, 0, self.width(), self.height()), self.border_radius, self.border_radius) x1 = QPointF(self.label_width + float(self.height() / 3), float(self.height() * 0.45)) x2 = QPointF( self.label_width + float(self.height() * (0.66 + self.rate) / 2), float(self.height() * 0.55)) x3 = QPointF(self.width() - float(self.height() / 3), float(self.height() * 0.45)) check_path = QPainterPath() check_path.moveTo(x1) check_path.lineTo(x2) check_path.lineTo(x3) pen = QPen(self.text_color, self.drop_thick, Qt.SolidLine) painter.setPen(pen) painter.drawPath(check_path)
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHints(QPainter.Antialiasing) painter.setPen(Qt.NoPen) painter.setBrush(self.back_color) painter.drawRoundedRect(QRect(0, 0, self.width(), self.height()), self.border_radius, self.border_radius)
def draw_validation_rect(painter: QPainter, geom: NodeGeometry, model: NodeDataModel, graphics_object: NodeGraphicsObject, node_style: NodeStyle): """ Draw validation rect Parameters ---------- painter : QPainter geom : NodeGeometry model : NodeDataModel graphics_object : NodeGraphicsObject node_style : NodeStyle """ model_validation_state = model.validation_state() if model_validation_state == NodeValidationState.valid: return color = (node_style.selected_boundary_color if graphics_object.isSelected() else node_style.normal_boundary_color) if geom.hovered: p = QPen(color, node_style.hovered_pen_width) else: p = QPen(color, node_style.pen_width) painter.setPen(p) # Drawing the validation message background if model_validation_state == NodeValidationState.error: painter.setBrush(node_style.error_color) else: painter.setBrush(node_style.warning_color) radius = 3.0 diam = node_style.connection_point_diameter boundary = QRectF( -diam, -diam + geom.height - geom.validation_height, 2.0 * diam + geom.width, 2.0 * diam + geom.validation_height, ) painter.drawRoundedRect(boundary, radius, radius) painter.setBrush(Qt.gray) # Drawing the validation message itself error_msg = model.validation_message() f = painter.font() metrics = QFontMetrics(f) rect = metrics.boundingRect(error_msg) position = QPointF( (geom.width - rect.width()) / 2.0, geom.height - (geom.validation_height - diam) / 2.0 ) painter.setFont(f) painter.setPen(node_style.font_color) painter.drawText(position, error_msg)
def paintEvent(self, paintEvent): pen1 = QPen() pen1.setColor(self.color) painter = QPainter(self) painter.setPen(pen1) painter.begin(self) painter.drawRoundedRect(self.boundingRect(), 10, 10) # 绘制函数 painter.end()
def paintEvent(self, event): """Paint the background, range bar and splitters. Parameters ---------- event : qtpy.QEvent Event from the Qt context. """ painter, w, h = QPainter(self), self.width(), self.height() half_width = self.slider_width / 2 halfdiff = int(w / 2 - half_width) # Background painter.setPen(self.background_color) painter.setBrush(self.background_color) painter.drawRoundedRect(halfdiff, 0, self.slider_width, h, 2, 2) # Range Bar painter.setPen(self.bar_color) painter.setBrush(self.bar_color) if self.collapsed: painter.drawRect( halfdiff, h - self.display_max, self.slider_width, self.display_max, ) else: painter.drawRect( halfdiff, h - self.display_max, self.slider_width, self.display_max - self.display_min, ) painter.setRenderHints(QPainter.Antialiasing) # Splitters painter.setPen(self.handle_border_color) painter.setBrush(self.handle_color) painter.drawEllipse( int(w / 2 - self.handle_radius), h - self.display_min - self.handle_radius, self.handle_width, self.handle_width, ) # upper painter.drawEllipse( int(w / 2 - self.handle_radius), h - self.display_max - self.handle_radius, self.handle_width, self.handle_width, ) # lower
def paintEvent(self, event): bw = float(self._border_width) br = self._border_radius val = self.value() if self.orientation() == Qt.Horizontal: w = QStyle.sliderPositionFromValue(self.minimum(), self.maximum(), val, self.width()) h = self.height() rect = QRectF(bw / 2, bw / 2, w - bw, h - bw) else: w = self.width() h = self.height() - QStyle.sliderPositionFromValue( self.minimum(), self.maximum(), val, self.height()) rect = QRectF(bw / 2, h - bw / 2, w - bw, self.height() - bw) p = QPainter(self) p.setRenderHint(QPainter.Antialiasing) # draw the load meter value bar p.setPen(Qt.transparent) p.setBrush(self.gradient) p.drawRoundedRect(rect, br, br) # draw the border p.setBrush(Qt.transparent) border_pen = QPen() border_pen.setWidth(bw) border_pen.setColor(self._border_color) p.setPen(border_pen) rect = QRectF(bw / 2, bw / 2, self.width() - bw, self.height() - bw) p.drawRoundedRect(rect, br, br) # draw the load percentage text p.setPen(self._text_color) if self.orientation() == Qt.Vertical: p.rotate(-90) p.drawText(-self.height(), 0, self.height(), self.width(), Qt.AlignCenter, self.text()) else: p.drawText(0, 0, self.width(), self.height(), Qt.AlignCenter, self.text())
def paintEvent(self, QPaintEvent): if not self._isSpinning: return self.updatePosition() painter = QPainter(self) painter.fillRect(self.rect(), Qt.transparent) painter.setRenderHint(QPainter.Antialiasing, True) if self._currentCounter >= self._numberOfLines: self._currentCounter = 0 painter.setPen(Qt.NoPen) for i in range(0, self._numberOfLines): painter.save() painter.translate(self._innerRadius + self._lineLength, self._innerRadius + self._lineLength) rotateAngle = float(360 * i) / float(self._numberOfLines) painter.rotate(rotateAngle) painter.translate(self._innerRadius, 0) distance = self.lineCountDistanceFromPrimary( i, self._currentCounter, self._numberOfLines) color = self.currentLineColor(distance, self._numberOfLines, self._trailFadePercentage, self._minimumTrailOpacity, self._color) # Compute the scaling factor to apply to the size and thickness # of the lines in the trail. if self._trailSizeDecreasing: sf = (self._numberOfLines - distance) / self._numberOfLines else: sf = 1 painter.setBrush(color) rect = QRect(0, round(-self._lineWidth / 2), round(sf * self._lineLength), round(sf * self._lineWidth)) painter.drawRoundedRect(rect, self._roundness, self._roundness, Qt.RelativeSize) painter.restore()
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))