def paintEvent(self, event): super().paintEvent(event) rect = QLine(self.x0, self.y0, self.x1, self.y1) painter = QPainter(self) painter.setPen(QPen(Qt.red, 2, Qt.SolidLine)) painter.drawLine(rect)
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) center = QPointF(self.width() / 2, self.height() / 2) radius = self.radius() ellipse_line_width = self.radius() * 60 / 512 # big ellipse pen = QPen() pen.setWidth(ellipse_line_width) pen.setColor(self.color) painter.setPen(pen) painter.drawEllipse(center, radius - pen.width() / 2, radius - pen.width() / 2) # dots pen = QPen() pen.setColor(QColor(0, 0, 0, 0)) painter.setPen(pen) brush = QBrush() brush.setStyle(Qt.SolidPattern) dot_size = radius * 200 / 1024 color = copy.copy(self.color) self._change_color(painter, brush, color, 0) painter.drawEllipse( QPointF((self.width() - radius - ellipse_line_width / 2) / 2, self.height() / 2), dot_size, dot_size) self._change_color(painter, brush, color, 15) painter.drawEllipse(center, dot_size, dot_size) self._change_color(painter, brush, color, 30) painter.drawEllipse( QPointF((self.width() + radius + ellipse_line_width / 2) / 2, self.height() / 2), dot_size, dot_size)
def paint(self, painter: QPainter): brush = QBrush(QColor("#007430")) painter.setBrush(brush) painter.setPen(Qt.NoPen) painter.setRenderHint(QPainter.Antialiasing) itemSize = self.size() painter.drawRoundedRect(0, 0, itemSize.width(), itemSize.height() - 10, 10, 10) if self.rightAligned: points = [ QPointF(itemSize.width() - 10.0, itemSize.height() - 10.0), QPointF(itemSize.width() - 20.0, itemSize.height()), QPointF(itemSize.width() - 30.0, itemSize.height() - 10.0), ] else: points = [ QPointF(10.0, itemSize.height() - 10.0), QPointF(20.0, itemSize.height()), QPointF(30.0, itemSize.height() - 10.0), ] painter.drawConvexPolygon(points)
def drawBackground(self, painter: QPainter, rect: QRectF): currentColor = self.backgroundBrush().color() if currentColor != self.backgroundColor: self.setBackgroundBrush(QBrush(self.backgroundColor)) super().drawBackground(painter, rect) if self._zoom <= self.gridZoomThreshold or not self.showGrid: return painter.setPen(QPen(self.gridColor, self.gridThickness)) lines = [] if self.gridSpacing.width() > 0: xStart = rect.left() - rect.left() % self.gridSpacing.width() while xStart <= rect.right(): line = QLineF(xStart, rect.bottom(), xStart, rect.top()) lines.append(line) xStart = xStart + self.gridSpacing.width() if self.gridSpacing.height() > 0: yStart = rect.top() - rect.top() % self.gridSpacing.height() while yStart <= rect.bottom(): line = QLineF(rect.left(), yStart, rect.right(), yStart) lines.append(line) yStart = yStart + self.gridSpacing.height() painter.drawLines(lines)
def paintEvent(self, event): """ Поскольку это полностью прозрачное фоновое окно, жесткая для поиска граница с прозрачностью 1 рисуется в событии перерисовывания, чтобы отрегулировать размер окна. """ super(FramelessWindow, self).paintEvent(event) painter = QPainter(self) painter.setPen(QPen(QColor(255, 255, 255, 1), 2 * self.Margins)) painter.drawRect(self.rect())
def paintEvent(self, event): rect = QRect(10, 20, 80, 60) path = QPainterPath() path.moveTo(20, 80) path.lineTo(20, 30) path.cubicTo(80, 0, 50, 50, 80, 80) startAngle = 30 * 16 arcLength = 120 * 16 painter = QPainter(self) painter.setPen(self.pen) painter.setBrush(self.brush) if self.antialiased: painter.setRenderHint(QPainter.Antialiasing) for x in range(0, self.width(), 100): for y in range(0, self.height(), 100): painter.save() painter.translate(x, y) if self.transformed: painter.translate(50, 50) painter.rotate(60.0) painter.scale(0.6, 0.9) painter.translate(-50, -50) if self.shape == RenderArea.Line: painter.drawLine(rect.bottomLeft(), rect.topRight()) elif self.shape == RenderArea.Points: painter.drawPoints(RenderArea.points) elif self.shape == RenderArea.Polyline: painter.drawPolyline(RenderArea.points) elif self.shape == RenderArea.Polygon: painter.drawPolygon(RenderArea.points) elif self.shape == RenderArea.Rect: painter.drawRect(rect) elif self.shape == RenderArea.RoundedRect: painter.drawRoundedRect(rect, 25, 25, Qt.RelativeSize) elif self.shape == RenderArea.Ellipse: painter.drawEllipse(rect) elif self.shape == RenderArea.Arc: painter.drawArc(rect, startAngle, arcLength) elif self.shape == RenderArea.Chord: painter.drawChord(rect, startAngle, arcLength) elif self.shape == RenderArea.Pie: painter.drawPie(rect, startAngle, arcLength) elif self.shape == RenderArea.Path: painter.drawPath(path) elif self.shape == RenderArea.Text: painter.drawText(rect, Qt.AlignCenter, "PySide 2\nQt %s" % qVersion()) elif self.shape == RenderArea.Pixmap: painter.drawPixmap(10, 10, self.pixmap) painter.restore() painter.setPen(self.palette().dark().color()) painter.setBrush(Qt.NoBrush) painter.drawRect(QRect(0, 0, self.width() - 1, self.height() - 1))
def draw(self, painter: QPainter): super().draw(painter) pen = painter.pen() pen.setColor(QColor('darkgrey')) painter.setPen(pen) w = self.width h = self.height painter.drawLine(w//2, h*3//4, w*13//14, h*3//12)
def draw(self, painter: QPainter): super().draw(painter) pen = painter.pen() pen.setColor(QColor('darkgrey')) painter.setPen(pen) w = self.width h = self.height x = int(w * 0.71) painter.drawLine(x, int(h * 0.48), x, int(h * 0.7))
def draw(self, painter: QPainter): super().draw(painter) pen = painter.pen() pen.setColor(QColor('darkgrey')) painter.setPen(pen) w = self.width h = self.height length = int(w * 0.2) x = int(w * 0.4) y = int(h * 0.58) painter.drawLine(x, y, x + length, y - length)
def paintEvent(self, event): size = self.size() # draw background painter = QPainter() painter.begin(self) painter.setRenderHint(QPainter.Antialiasing) painter.setPen(QColor(255, 255, 255, 255)) painter.setBrush(self.fill_color) painter.drawRect(0, 0, size.width(), size.height()) painter.end()
def assert_equal(self): __tracebackhide__ = True self.end() self.different_pixels = 0 actual_image: QImage = self.actual.device().toImage() expected_image: QImage = self.expected.device().toImage() diff_pixmap = QPixmap(actual_image.width(), actual_image.height()) diff = QPainter(diff_pixmap) try: white = QColor('white') diff.fillRect(0, 0, actual_image.width(), actual_image.height(), white) for x in range(actual_image.width()): for y in range(actual_image.height()): actual_colour = actual_image.pixelColor(x, y) expected_colour = expected_image.pixelColor(x, y) diff.setPen( self.diff_colour(actual_colour, expected_colour, x, y)) diff.drawPoint(x, y) finally: diff.end() diff_image: QImage = diff.device().toImage() display_diff(actual_image, diff_image, expected_image, self.different_pixels) if self.different_pixels == 0: return actual_image.save(str(self.work_dir / (self.name + '_actual.png'))) expected_image.save(str(self.work_dir / (self.name + '_expected.png'))) diff_path = self.work_dir / (self.name + '_diff.png') is_saved = diff_image.save(str(diff_path)) diff_width = self.diff_max_x - self.diff_min_x + 1 diff_height = self.diff_max_y - self.diff_min_y + 1 diff_section = QImage(diff_width, diff_height, QImage.Format_RGB32) diff_section_painter = QPainter(diff_section) try: diff_section_painter.drawPixmap(0, 0, diff_width, diff_height, QPixmap.fromImage(diff_image), self.diff_min_x, self.diff_min_y, diff_width, diff_height) finally: diff_section_painter.end() # To see an image dumped in the Travis CI log, copy the text from the # log, and paste it in test_pixmap_differ.test_decode_image. print(f'Encoded image of differing section ' f'({self.diff_min_x}, {self.diff_min_y}) - ' f'({self.diff_max_x}, {self.diff_max_y}):') print(encode_image(diff_section)) message = f'Found {self.different_pixels} different pixels, ' message += f'see' if is_saved else 'could not write' message += f' {diff_path.relative_to(Path(__file__).parent.parent)}.' assert self.different_pixels == 0, message
def create_icon(player_colour: QColor) -> QPixmap: size = 200 icon = QPixmap(size, size) icon.fill(Qt.transparent) painter = QPainter(icon) try: painter.setBrush(player_colour) pen = QPen() pen.setWidth(3) painter.setPen(pen) painter.drawEllipse(1, 1, size - 2, size - 2) finally: painter.end() return icon
def draw(self, painter: QPainter): super().draw(painter) pen = painter.pen() pen.setColor(QColor('darkgrey')) painter.setPen(pen) w = self.width h = self.height size = int(w * 0.06) x = int(w * 0.49) y = int(h * 0.47) painter.drawLine(x, y - size, x, y + size) painter.drawLine(x - size, y, x + size, y) x = int(w * 0.6) y = int(h * 0.37) painter.drawLine(x, y - size, x, y + size) painter.drawLine(x - size, y, x + size, y)
def paintEvent(self, event: QtGui.QPaintEvent) -> None: painter = QPainter(self) #painter.setPen(QPen(Qt.blue, 1, Qt.DashLine)) # Create transformation for text and other things that will be drawn transform = QTransform() # Rotation shiftX = self.width() // 2 shiftY = self.height() // 2 transform.translate(shiftX, shiftY) transform.rotate(self._rotate) transform.translate(-shiftX, -shiftY) # Scale, NOTICE! Scale change position of the text, i. e. size of frame (?) scale_x = self._scale[0] / 100 scale_y = self._scale[1] / 100 transform.scale(scale_x, scale_y) # Apply transformation painter.setTransform(transform) # Draw text painter.setFont(QFont('Times', 20, QFont.Bold)) painter.setPen( QPen( QColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)), 1 ) ) # Because of the scale size of the frame is changed, recalculate size according to scale width_tr = int(self.width() * (1 / scale_x)) height_tr = int(self.height() * (1 / scale_y)) painter.drawText(0, 0, width_tr, height_tr, Qt.AlignCenter | Qt.AlignTop, self._text) # Update transformation variables self._rotate += self._addRotation self._scale[0] += self._addScale[0] self._scale[1] += self._addScale[1] # Check bounds and keep variable in the loop if self._rotate >= max(self._rotationBounds) or self._rotate <= min(self._rotationBounds): self._addRotation *= (-1) if self._scale[0] >= max(self._scaleBounds[0]) or self._scale[0] <= min(self._scaleBounds[0]): self._addScale[0] *= (-1) if self._scale[1] >= max(self._scaleBounds[1]) or self._scale[1] <= min(self._scaleBounds[1]): self._addScale[1] *= (-1)
def __init__(self): # Sidebar icons are 28x28 points. Should be at least 56x56 pixels for # HiDPI display compatibility. They will be automatically made theme # aware, so you need only provide a grayscale image, where white is # the color of the shape. icon = QImage(56, 56, QImage.Format_RGB32) icon.fill(0) # Render an "H" as the example icon p = QPainter() p.begin(icon) p.setFont(QFont("Open Sans", 56)) p.setPen(QColor(255, 255, 255, 255)) p.drawText(QRectF(0, 0, 56, 56), Qt.AlignCenter, "H") p.end() SidebarWidgetType.__init__(self, icon, "Hello")
def paintEvent(self, event): super(QtBubbleLabel, self).paintEvent(event) painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) # 抗锯齿 rectPath = QPainterPath() # 圆角矩形 height = self.height() - 8 # 往上偏移8 rectPath.addRoundedRect(QRectF(0, 0, self.width(), height), 5, 5) x = self.width() / 5 * 4 # 边框画笔 painter.setPen( QPen(self.BorderColor, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) # 背景画刷 painter.setBrush(self.BackgroundColor) # 绘制形状 painter.drawPath(rectPath)
def assert_equal(self): __tracebackhide__ = True self.end() self.different_pixels = 0 actual_image: QImage = self.actual.device().toImage() expected_image: QImage = self.expected.device().toImage() diff_pixmap = QPixmap(actual_image.width(), actual_image.height()) diff = QPainter(diff_pixmap) try: white = QColor('white') diff.fillRect(0, 0, actual_image.width(), actual_image.height(), white) for x in range(actual_image.width()): for y in range(actual_image.height()): actual_colour = actual_image.pixelColor(x, y) expected_colour = expected_image.pixelColor(x, y) diff.setPen( self.diff_colour(actual_colour, expected_colour, x, y)) diff.drawPoint(x, y) finally: diff.end() diff_image: QImage = diff.device().toImage() display_diff(actual_image, diff_image, expected_image, self.different_pixels) if self.different_pixels == 0: return actual_image.save(str(self.work_dir / (self.name + '_actual.png'))) expected_image.save(str(self.work_dir / (self.name + '_expected.png'))) diff_path = self.work_dir / (self.name + '_diff.png') is_saved = diff_image.save(str(diff_path)) diff_width = self.diff_max_x - self.diff_min_x + 1 diff_height = self.diff_max_y - self.diff_min_y + 1 diff_section = QImage(diff_width, diff_height, QImage.Format_RGB32) diff_section_painter = QPainter(diff_section) try: diff_section_painter.drawPixmap(0, 0, diff_width, diff_height, QPixmap.fromImage(diff_image), self.diff_min_x, self.diff_min_y, diff_width, diff_height) finally: diff_section_painter.end() message = f'Found {self.different_pixels} different pixels.' assert self.different_pixels == 0, message
def drawText(self, p: QPainter, innerRect: QRectF, innerRadius: float, value: float): if not self.m_format: return f = QFont(self.font()) f.setPixelSize(10) fm = QFontMetricsF(f) maxWidth = fm.width(self.valueToText(self.m_max)) delta = innerRadius / maxWidth fontSize = f.pixelSize() * delta * 0.75 f.setPixelSize(int(fontSize)) p.setFont(f) textRect = QRectF(innerRect) p.setPen(self.palette().text().color()) p.drawText(textRect, Qt.AlignCenter, self.valueToText(value))
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing, self.antialiased) painter.translate(self.width() / 2, self.height() / 2) for diameter in range(0, 256, 9): delta = abs((self.frameNo % 128) - diameter / 2) alpha = 255 - (delta * delta) / 4 - diameter if alpha > 0: painter.setPen(QPen(QColor(0, diameter / 2, 127, alpha), 3)) if self.floatBased: painter.drawEllipse( QRectF(-diameter / 2.0, -diameter / 2.0, diameter, diameter)) else: painter.drawEllipse( QRect(-diameter / 2, -diameter / 2, diameter, diameter))
def paint(self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex) -> None: itemOption = QStyleOptionViewItem(option) # disable focus outline if itemOption.state & QStyle.State_HasFocus: itemOption.state ^= QStyle.State_HasFocus # hover whole row if index.row() == option.styleObject.hoverIndexRow: itemOption.state |= QStyle.State_MouseOver super().paint(painter, itemOption, index) # draw lines around numeric columns if index.column() in (5, 12): oldpen = painter.pen() painter.setPen(self.linepen) painter.drawLine(itemOption.rect.topRight() + QPoint(0, 0), itemOption.rect.bottomRight() + QPoint(0, 0)) painter.setPen(oldpen)
def paintEvent(self, event): sineTable = [ 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38 ] metrics = QFontMetrics(self.font()) x = (self.width() - metrics.horizontalAdvance(self.text)) / 2 y = (self.height() + metrics.ascent() - metrics.descent()) / 2 color = QColor() painter = QPainter(self) for i in range(len(self.text)): index = (self.step + i) % 16 color.setHsv((15 - index) * 16, 255, 191) painter.setPen(color) painter.drawText(x, y - ((sineTable[index] * metrics.height()) / 400), str(self.text[i])) x += metrics.horizontalAdvance(self.text[i])
def shape_to_pixelmap(item_type, pen, brush, shape) -> QPixmap: pixmap = QPixmap(50, 50) pixmap.fill(Qt.transparent) painter = QPainter(pixmap) painter.setRenderHint(QPainter.Antialiasing) painter.setPen(pen) painter.setBrush(brush) if item_type == QGraphicsRectItem.type(QGraphicsRectItem()): painter.drawRect(QRect(10, 15, 30, 20)) elif item_type == QGraphicsEllipseItem.type(QGraphicsEllipseItem()): painter.drawEllipse(QRect(10, 10, 30, 30)) elif item_type == QGraphicsPolygonItem.type(QGraphicsPolygonItem()): if shape.polygon().size() == 3: painter.drawPolygon(QPolygon([QPoint(10, 40), QPoint(40, 40), QPoint(25, 10)])) else: painter.drawPolygon(QPolygon([QPoint(12, 40), QPoint(23, 36), QPoint(37, 24), QPoint(23, 12), QPoint(7, 16)])) elif item_type == QGraphicsLineItem.type(QGraphicsLineItem()): painter.drawLine(QLine(10, 40, 40, 10)) return pixmap
def lineNumberAreaPaintEvent(self, event): painter = QPainter(self.line_number_area) painter.fillRect(event.rect(), Qt.lightGray) block = self.firstVisibleBlock() block_number = block.blockNumber() offset = self.contentOffset() top = self.blockBoundingGeometry(block).translated(offset).top() bottom = top + self.blockBoundingRect(block).height() while block.isValid() and top <= event.rect().bottom(): if block.isVisible() and bottom >= event.rect().top(): number = str(block_number + 1) painter.setPen(Qt.black) width = self.line_number_area.width() height = self.fontMetrics().height() painter.drawText(0, top, width, height, Qt.AlignRight, number) block = block.next() top = bottom bottom = top + self.blockBoundingRect(block).height() block_number += 1
def paintEvent(self, event): painter = QPainter(self) painter.fillRect(event.rect(), self.numberBarColor) block = self.editor.firstVisibleBlock() # Iterate over all visible text blocks in the document. while block.isValid(): blockNumber = block.blockNumber() block_top = self.editor.blockBoundingGeometry( block).translated(self.editor.contentOffset()).top() # Check if the position of the block is out side of the visible area. if not block.isVisible() or block_top >= event.rect().bottom(): break # We want the line number for the selected line to be bold. if blockNumber == self.editor.textCursor().blockNumber(): self.font.setBold(True) painter.setPen(bnstyles["blockSelected"]) else: self.font.setBold(False) painter.setPen(bnstyles["blockNormal"]) painter.setFont(self.font) # Draw the line number right justified at the position of the line. paint_rect = QRect(0, block_top, self.width(), self.editor.fontMetrics().height()) painter.drawText(paint_rect, Qt.AlignLeft, str(blockNumber + 1)) block = block.next() painter.end() QWidget.paintEvent(self, event)
def drawValue(self, p: QPainter, baseRect: QRectF, value: float, delta: float): if value == self.m_min: return if self.m_barStyle == self.BarStyle.EXPAND: p.setBrush(self.palette().highlight()) p.setPen(QPen(self.palette().shadow().color(), self.m_dataPenWidth)) radius = (baseRect.height() / 2) / delta p.drawEllipse(baseRect.center(), radius, radius) return elif self.m_barStyle == self.BarStyle.LINE: p.setPen( QPen(self.palette().highlight().color(), self.m_dataPenWidth)) p.setBrush(Qt.NoBrush) if value == self.m_max: p.drawEllipse( baseRect.adjusted(self.m_outlinePenWidth / 2, self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2)) else: arcLength = 360 / delta p.drawArc( baseRect.adjusted(self.m_outlinePenWidth / 2, self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2), int(self.m_nullPosition * 16), int(-arcLength * 16)) return dataPath = QPainterPath() dataPath.setFillRule(Qt.WindingFill) if value == self.m_max: dataPath.addEllipse(baseRect) else: arcLength = 360 / delta dataPath.moveTo(baseRect.center()) dataPath.arcTo(baseRect, self.m_nullPosition, -arcLength) dataPath.lineTo(baseRect.center()) p.setBrush(self.palette().highlight()) p.setPen(QPen(self.palette().shadow().color(), self.m_dataPenWidth)) p.drawPath(dataPath)
def drawBase(self, p: QPainter, baseRect: QRectF): if self.m_barStyle == self.BarStyle.DONUT: p.setPen( QPen(self.palette().shadow().color(), self.m_outlinePenWidth)) p.setBrush(self.palette().base()) p.drawEllipse(baseRect) elif self.m_barStyle == self.BarStyle.LINE: p.setPen( QPen(self.palette().base().color(), self.m_outlinePenWidth)) p.setBrush(Qt.NoBrush) p.drawEllipse( baseRect.adjusted(self.m_outlinePenWidth / 2, self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2, -self.m_outlinePenWidth / 2)) elif self.m_barStyle in (self.BarStyle.PIE, self.BarStyle.EXPAND): p.setPen( QPen(self.palette().base().color(), self.m_outlinePenWidth)) p.setBrush(self.palette().base()) p.drawEllipse(baseRect)
def paintEvent(self, event): painter = QPainter(self) painter.fillRect(self.rect(), Qt.black) if self.pixmap.isNull(): painter.setPen(Qt.white) painter.drawText(self.rect(), Qt.AlignCenter, "Rendering initial image, please wait...") return if self.curScale == self.pixmapScale: painter.drawPixmap(self.pixmapOffset, self.pixmap) else: scaleFactor = self.pixmapScale / self.curScale newWidth = int(self.pixmap.width() * scaleFactor) newHeight = int(self.pixmap.height() * scaleFactor) newX = self.pixmapOffset.x() + (self.pixmap.width() - newWidth) / 2 newY = self.pixmapOffset.y() + (self.pixmap.height() - newHeight) / 2 painter.save() painter.translate(newX, newY) painter.scale(scaleFactor, scaleFactor) exposed, _ = painter.transform().inverted() exposed = exposed.mapRect(self.rect()).adjusted(-1, -1, 1, 1) painter.drawPixmap(exposed, self.pixmap, exposed) painter.restore() text = "Use mouse wheel or the '+' and '-' keys to zoom. Press and " \ "hold left mouse button to scroll." metrics = painter.fontMetrics() textWidth = metrics.horizontalAdvance(text) painter.setPen(Qt.NoPen) painter.setBrush(QColor(0, 0, 0, 127)) painter.drawRect((self.width() - textWidth) / 2 - 5, 0, textWidth + 10, metrics.lineSpacing() + 5) painter.setPen(Qt.white) painter.drawText((self.width() - textWidth) / 2, metrics.leading() + metrics.ascent(), text)
def DrawWidget(self, Painter: QtGui.QPainter, Option, Index): state = Option.state if state & self._style.State_Enabled and state & self._style.State_Selected: # Selected color = QtGui.QColor(self._theme.get("ui-02")) border = QtGui.QColor(self._theme.get("ui-01")) elif state & self._style.State_Enabled and state & self._style.State_Active: # Normal color = QtGui.QColor(self._theme.get("ui-01")) border = QtGui.QColor(self._theme.get("ui-02")) elif state & self._style.State_Enabled: # Inactive color = QtGui.QColor(self._theme.get("ui-01")) border = QtGui.QColor(self._theme.get("ui-02")) else: # Disabled color = QtGui.QColor(self._theme.get("disabled-02")) border = QtGui.QColor(self._theme.get("disabled-02")) Painter.setPen(color) self._style.drawPrimitive(self._style.PE_PanelItemViewItem, Option, Painter, Option.widget) Painter.fillRect(Option.rect, (color)) Painter.setPen(QtGui.QColor(self._theme.get("text-02"))) items = self.getData(Index) self.DrawCover(Painter, Option) self.DrawTop(Painter, Option, items[0]) self.DrawMid(Painter, Option, items[1]) self.DrawBottom(Painter, Option, [items[2], items[3], items[4]]) Painter.setPen(border) Painter.drawLine(QPoint(0, Option.rect.y() + 63), QPoint(Option.rect.width(), Option.rect.y() + 63))
def draw(self, painter: QPainter): render_display(self.display, painter) pen = QPen() pen.setWidth(self.width // 50) pen.setCapStyle(Qt.PenCapStyle.RoundCap) painter.setPen(pen)
def paintEvent(self, ev): # print("Radio paintEventCalled") # print("size =", self.paintSize) opt = QStyleOption() opt.initFrom(self) painter = QPainter(self) # print("minimum size : ", self.minimumSize()) # print("radio: hasHforW : ", self.hasHeightForWidth()) # print("radio: size : ", self.size()) # print("radio : minimumSizeHint() :", self.minimumSizeHint()) # s = self.style() # s.drawPrimitive(QStyle.PE_Widget, opt, painter, self) # self.computeSize() size = self.paintSize # size = np.min([1/8 * self.width(), self.height()/4]) fontsizefactor = self.fontsizefactor linewidth = 1 painter.setRenderHint(QPainter.Antialiasing) pointColor = QColor(painter.pen().color()) bgColor = QColor(painter.background().color()) # bgColor = QColor("white") painter.setBrush(QBrush(QColor("transparent"))) painter.setPen(QPen(QColor(pointColor), linewidth)) # painter.setBackgroundMode(Qt.TransparentMode) center = QtCore.QPoint(int(self.width() / 2), int(self.height() / 2)) self.center = center self.radius = size painter.drawEllipse(center, size, size) margin = .4 * size # painter.drawRect(text_rect) # self.text() fontsize = size * fontsizefactor # self.fontsize = fontsize f = painter.font() f.setPointSizeF(fontsize) painter.setFont(f) text_rect = QRectF(center.x() + size + margin, center.y() - fontsize, 100, 2 * fontsize) # painter.drawRect(text_rect) painter.drawText(text_rect, Qt.AlignLeft | Qt.AlignVCenter, self.text()) self.textRect = text_rect if self.isChecked(): painter.setBrush(QBrush(QColor(int(colors[self._ID], 0)))) # painter.setPen(QPen(Qt.NoPen)) painter.drawEllipse(center, size, size) # painter.drawLine(QtCore.QPointF(self.width()/2, 0), QtCore.QPointF(self.width()/2, self.height())) pass