def getRoundedRectPath(self, i, yTranslation, side): rect = QRect(self.ioList[i][0], self.ioList[i][1] + yTranslation, self.ioWidth, self.ioHeight, 2, 2) path = QPainterPath() path.setFillRule(Qt.WindingFill) path.addRoundedRect(self.ioList[i][0], self.ioList[i][1] + yTranslation, self.ioWidth, self.ioHeight, 2, 2) #Remove rounded edges on left or right side if side == 'left': path.addRect(self.ioList[i][0], self.ioList[i][1] + yTranslation, 2, 2) path.addRect(self.ioList[i][0], self.ioList[i][1] + yTranslation + self.ioHeight - 2, 2, 2) else: path.addRect(self.ioList[i][0] + self.ioWidth - 2, self.ioList[i][1] + yTranslation, 2, 2) path.addRect(self.ioList[i][0] + self.ioWidth - 2, self.ioList[i][1] + yTranslation + self.ioHeight - 2, 2, 2) return path
def setPixmap(self, path): if not os.path.exists(path): self._image = '' self._pixmap = None return self._image = path size = min(self.width(), self.height()) - self.padding # 需要边距的边框 radius = int(size / 2) image = QImage(size, size, QImage.Format_ARGB32_Premultiplied) image.fill(Qt.transparent) # 填充背景为透明 pixmap = QPixmap(path).scaled(size, size, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation) # QPainter painter = QPainter() painter.begin(image) painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QPainter.SmoothPixmapTransform, True) # QPainterPath path = QPainterPath() path.addRoundedRect(0, 0, size, size, radius, radius) # 切割圆 painter.setClipPath(path) painter.drawPixmap(0, 0, pixmap) painter.end() self._pixmap = QPixmap.fromImage(image) self.update()
def shape(self, object): path = QPainterPath() if (not object.cell().isEmpty()): path.addRect(self.boundingRect(object)) else: x = object.shape() if x == MapObject.Rectangle: bounds = object.bounds() if (bounds.isNull()): path.addEllipse(bounds.topLeft(), 20, 20) else: path.addRoundedRect(bounds, 10, 10) elif x == MapObject.Polygon or x == MapObject.Polyline: pos = object.position() polygon = object.polygon().translated(pos) screenPolygon = self.pixelToScreenCoords_(polygon) if (object.shape() == MapObject.Polygon): path.addPolygon(screenPolygon) else: for i in range(1, screenPolygon.size()): path.addPolygon( self.lineToPolygon(screenPolygon[i - 1], screenPolygon[i])) path.setFillRule(Qt.WindingFill) elif x == MapObject.Ellipse: bounds = object.bounds() if (bounds.isNull()): path.addEllipse(bounds.topLeft(), 20, 20) else: path.addEllipse(bounds) return path
def painterPath(self): rect = self._rect radius = self._RADIUS path = QPainterPath() path.addRoundedRect(rect, radius, radius) return path
def paintEvent(self, event): # 圆角以及背景色 super(NotificationItem, self).paintEvent(event) painter = QPainter(self) path = QPainterPath() path.addRoundedRect(QRectF(self.rect()), 6, 6) painter.fillPath(path, Qt.white)
def paintEvent(self, event): # Закругленные углы и цвет фона super(NotificationItem, self).paintEvent(event) painter = QPainter(self) path = QPainterPath() path.addRoundedRect(QRectF(self.rect()), 6, 6) painter.fillPath(path, Qt.white)
def _paint_tooltip(self, painter: QPainter, point: QPoint, y: int, x: int, plot_name: str, color: QColor, vertical_offset: int) -> int: painter.setPen(QPen(QColor(40, 40, 40))) res = self._tooltip_func(y, x, plot_name) painter.setBrush(self._default_tooltip_brush) point = QPoint(point.x() + self._tooltip_horizontal_offset, point.y() + vertical_offset) color = QColor(min(color.red() * 1.4, 255), min(color.green() * 1.4, 255), min(color.blue() * 1.4, 255), 200) if res is not None: lines: List = res.split('\n') lengths = [len(l) for l in lines] fm = QFontMetrics(self.font) width = fm.width(lines[lengths.index(max(lengths))]) height = fm.height() * len(lines) path = QPainterPath() path.addRoundedRect( QRectF(QPointF(point.x() - 5, point.y() - 5), QSizeF(width + 10, height + 10)), 10., 10.) painter.fillPath(path, color) painter.drawPath(path) painter.drawText(QRect(point, QSize(width, height)), xor(Qt.AlignLeft, Qt.AlignTop), res) return height + 11 return 0
def addPort(self, name, isOutput = False, flags = 0, ptr = None): port = QNEPort(self) port.setName(name) port.setIsOutput(isOutput) port.setNEBlock(self) port.setPortFlags(flags) port.setPtr(ptr) fontmetrics = QFontMetrics(self.scene().font()); width = fontmetrics.width(name) height = fontmetrics.height() if width > self.width - self.horzMargin: self.width = width + self.horzMargin self.height += height path = QPainterPath() path.addRoundedRect(-self.width/2, -self.height/2, self.width, self.height, 5, 5) self.setPath(path) y = -self.height / 2 + self.vertMargin + port.radius() for port_ in self.childItems(): if port_.type() != QNEPort.Type: continue if port_.isOutput(): port_.setPos(self.width/2 + port.radius(), y) else: port_.setPos(-self.width/2 - port.radius(), y) y += height; return port
def draw_tags(self, painter: QPainter, from_ind: int, to_ind: int) -> None: """ Draw the tags between two particular indices. """ for ind in range(from_ind, to_ind): i_r = self.tags[ind].rect text_pos = i_r.topLeft() + QPointF( TAG_TEXT_HORIZONTAL_PADDING, self.fontMetrics().ascent() + ((i_r.height() - self.fontMetrics().height()) // 2), ) # draw rect painter.setPen(EDIT_TAG_BORDER_COLOR) path = QPainterPath() path.addRoundedRect(i_r, TAG_HEIGHT // 2, TAG_HEIGHT // 2) painter.fillPath(path, EDIT_TAG_BACKGROUND_COLOR) painter.drawPath(path) # draw text painter.setPen(EDIT_TAG_TEXT_COLOR) painter.drawText(text_pos, self.tags[ind].text) # calc cross rect i_cross_r = TagsLineEdit.compute_cross_rect(i_r) pen = painter.pen() pen.setWidth(2) painter.setPen(pen) painter.drawLine( QLineF(i_cross_r.topLeft(), i_cross_r.bottomRight())) painter.drawLine( QLineF(i_cross_r.bottomLeft(), i_cross_r.topRight()))
def shape(self, object): path = QPainterPath() if (not object.cell().isEmpty()): path.addRect(self.boundingRect(object)) else: x = object.shape() if x==MapObject.Rectangle: bounds = object.bounds() if (bounds.isNull()): path.addEllipse(bounds.topLeft(), 20, 20) else: path.addRoundedRect(bounds, 10, 10) elif x==MapObject.Polygon or x==MapObject.Polyline: pos = object.position() polygon = object.polygon().translated(pos) screenPolygon = self.pixelToScreenCoords_(polygon) if (object.shape() == MapObject.Polygon): path.addPolygon(screenPolygon) else: for i in range(1, screenPolygon.size()): path.addPolygon(self.lineToPolygon(screenPolygon[i - 1], screenPolygon[i])) path.setFillRule(Qt.WindingFill) elif x==MapObject.Ellipse: bounds = object.bounds() if (bounds.isNull()): path.addEllipse(bounds.topLeft(), 20, 20) else: path.addEllipse(bounds) return path
def __init__(self, antialiasing=True): super(Label, self).__init__(*args, **kwargs) self.Antialiasing = antialiasing self.setMaximumSize(50, 50) self.setMinimumSize(50, 50) self.radius = 25 self.target = QPixmap(self.size()) self.target.fill(Qt.transparent) p = QPixmap(self.image).scaled(50, 50, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation) painter = QPainter(self.target) if self.Antialiasing: painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QPainter.HighQualityAntialiasing, True) painter.setRenderHint(QPainter.SmoothPixmapTransform, True) path = QPainterPath() path.addRoundedRect(0, 0, self.width(), self.height(), self.radius, self.radius) painter.setClipPath(path) painter.drawPixmap(0, 0, p) self.setPixmap(self.target)
def paint(self, painter, option, widget): pen = QPen(QColor('#455A64'), 5) painter.setPen(pen) painter.setRenderHint(QPainter.Antialiasing) time = self.parent.scene().views()[0].parent( ).game_control.timer.time.toString('mm:ss') rect = QRectF(self.x, self.y, self.width, self.height) string = f'Congratulations, you have found a solution in {time}! Use the New Game button to start over.' path = QPainterPath() path.addRoundedRect(rect, 10, 10) painter.drawPath(path) fill_color = QColor('#CFD8DC') fill_color.setAlphaF(0.9) fill_brush = QBrush(fill_color, Qt.SolidPattern) painter.fillPath(path, fill_brush) font_pen = QPen(Qt.black, 1) painter.setPen(font_pen) font = (QFont('Helvetica', 14, 50)) painter.setFont(font) painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap, string)
def paintEvent(self, event): super(FramelessWindow, self).paintEvent(event) m = 9 path = QPainterPath() path.setFillRule(Qt.WindingFill) path.addRect(m, m, self.width() - m * 2, self.height() - m * 2) painter = QPainter(self) painter.fillPath(path, QBrush(Qt.white)) color = QColor(100, 100, 100, 100) for i in range(m): path = QPainterPath() path.setFillRule(Qt.WindingFill) path.addRoundedRect(m - i, m - i, self.width() - (m - i) * 2, self.height() - (m - i) * 2, 1, 1) color.setAlpha(100 - 10 * i) painter.setPen(QPen(color, 1, Qt.SolidLine)) painter.drawRoundedRect( QRect(m - i, m - i, self.width() - (m - i) * 2, self.height() - (m - i) * 2), 0, 0)
def __init__(self, *args, antialiasing=True, **kwargs): super(Label, self).__init__(*args, **kwargs) self.Antialiasing = antialiasing self.setMaximumSize(200, 200) self.setMinimumSize(200, 200) self.radius = 100 #####################核心实现######################### self.target = QPixmap(self.size()) # 大小和控件一样 self.target.fill(Qt.transparent) # 填充背景为透明 p = QPixmap("head.jpg").scaled( # 加载图片并缩放和控件一样大 200, 200, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation) painter = QPainter(self.target) if self.Antialiasing: # 抗锯齿 painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QPainter.HighQualityAntialiasing, True) painter.setRenderHint(QPainter.SmoothPixmapTransform, True) # painter.setPen(# 测试圆圈 # QPen(Qt.red, 5, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) path = QPainterPath() path.addRoundedRect(0, 0, self.width(), self.height(), self.radius, self.radius) #**** 切割为圆形 ****# painter.setClipPath(path) # painter.drawPath(path) # 测试圆圈 painter.drawPixmap(0, 0, p) self.setPixmap(self.target)
def paintEvent(self, e): w = self.width() h = self.height() if self.enable_pulse == True: l = (w - 3) * 0.2 bar_start = ((w - 3) - l) * self.value else: l = (w - 3) * self.value bar_start = 0 qp = QPainter() qp.begin(self) color = QColor(0, 0, 0) color.setNamedColor('#d4d4d4') qp.setBrush(color) path = QPainterPath() path.addRoundedRect(QRectF(0, 0, w, h), 0, 0) qp.fillPath(path, QColor(206, 206, 206)) path = QPainterPath() path.addRoundedRect(QRectF(bar_start, 3, l, h - 6), 5, 5) qp.fillPath(path, QColor(71, 142, 216)) #path.addPolygon(QPolygonF([QPoint(0,0), QPoint(10,0), QPoint(10,10), QPoint(10,0)])); #qp.setBrush(QColor(71 , 142, 216)) #path.addPolygon(QPolygonF([QPoint(0,0), QPoint(50,0), QPoint(40,10), QPoint(10,0)])) #qp.setBrush(QColor(71 , 142, 216)) #qp.setBrush(QColor(206 , 207, 206)) qp.end()
def set_rounded_pixmap(self): # Получаем минимальную высоту, которую может занимать Label size = self.picture_label.minimumSizeHint().height() radius = size // 2 color = QColor(*self.info[5]) # Создаём прозрачный QPixmap, на который будем накладывать иконку target = QPixmap(QSize(size, size)) target.fill(Qt.transparent) painter = QPainter() painter.begin(target) pixmap = QPixmap(QSize(size, size)) pixmap.fill(color) # Создаём объект, который будет хранить инструкции для рисования круга # В данном случае можно было обойтись без него, он используется для рисования # более сложных фигур, особенно когда нужно рисовать их несколько раз path = QPainterPath() path.addRoundedRect(0, 0, size, size, radius, radius) painter.setClipPath(path) # Накладываем содержимое объекта pixmap на target # В данном случае накладываем круг на прозрачное изображение painter.drawPixmap(0, 0, pixmap) painter.end() self.picture_label.setPixmap(target)
def draw_bg(self, qp, rect, text): path = QPainterPath() # add container path.addRoundedRect(rect, 4, 4) if self.isEnabled(): highlight_color, bg_color, text_color = ( self.settings['highlight'], self.settings['bg'], self.settings['text']) else: highlight_color, bg_color, text_color = ( self.settings['highlight_disabled'], self.settings['bg_disabled'], self.settings['text_disabled']) qp.setPen(QPen(highlight_color, 2)) qp.fillPath(path, bg_color) # add close button circle_size = rect.height() / 1.8 pen_size = 2 qp.setPen(QPen(text_color, pen_size, Qt.SolidLine)) rect = QRectF( rect.right() - circle_size - self.settings['padding-x'] / 2, rect.top() + (rect.height() - circle_size) / 2, circle_size, circle_size) path.addEllipse(rect) qp.drawPath(path) # draw cross inside_rect = QRectF(rect) inside_rect.adjust(pen_size, pen_size, -pen_size, -pen_size) qp.drawLine(inside_rect.topLeft(), inside_rect.bottomRight()) qp.drawLine(inside_rect.bottomLeft(), inside_rect.topRight()) self.close_rectangles[text] = rect
def paint(self, painter: QPainter, option: 'QStyleOptionGraphicsItem', widget: Optional[QWidget] = ...) -> None: # content rect = self.rect() path_content = QPainterPath() path_content.setFillRule(Qt.WindingFill) path_content.addRoundedRect(rect, self.edge_roundness, self.edge_roundness) painter.setPen(Qt.NoPen) painter.setBrush(self._brush_background) painter.drawPath(path_content.simplified()) # outline path_outline = QPainterPath() path_outline.addRoundedRect(rect, self.edge_roundness, self.edge_roundness) painter.setPen( self._pen_default if not self.isSelected() else self._pen_selected) painter.setBrush(Qt.NoBrush) painter.drawPath(path_outline.simplified()) for handle in self.handles.values(): path_handle = QPainterPath() path_handle.addRect(handle) painter.drawPath(path_handle)
def paintEvent(self, event): super(CAvatar, self).paintEvent(event) # 画笔 painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QPainter.HighQualityAntialiasing, True) painter.setRenderHint(QPainter.SmoothPixmapTransform, True) # 绘制 path = QPainterPath() diameter = min(self.width(), self.height()) if self.shape == self.Circle: radius = int(diameter / 2) elif self.shape == self.Rectangle: radius = 4 halfW = self.width() / 2 halfH = self.height() / 2 painter.translate(halfW, halfH) path.addRoundedRect( QRectF(-halfW, -halfH, diameter, diameter), radius, radius) painter.setClipPath(path) # 如果是动画效果 if self.rotateAnimation.state() == QPropertyAnimation.Running: painter.rotate(self._angle) # 旋转 painter.drawPixmap( QPointF(-self.pixmap.width() / 2, -self.pixmap.height() / 2), self.pixmap) else: painter.drawPixmap(-int(halfW), -int(halfH), self.pixmap) # 如果在加载 if self.loadingTimer.isActive(): diameter = 2 * self.pradius painter.setBrush( QColor(45, 140, 240, (1 - self.pradius / 10) * 255)) painter.setPen(Qt.NoPen) painter.drawRoundedRect( QRectF(-self.pradius, -self.pradius, diameter, diameter), self.pradius, self.pradius)
def paintEvent(self, event): # 设置阴影 painter_path = QPainterPath() painter_path.setFillRule(Qt.WindingFill) painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) painter.fillPath(painter_path, QBrush(Qt.white)) # 阴影颜色 color = QColor(0, 250, 255, 50) for i in range(10): i_path = QPainterPath() i_path.setFillRule(Qt.WindingFill) ref = QRectF(10 - i, 10 - i, self.width() - (10 - i) * 2, self.height() - (10 - i) * 2) i_path.addRoundedRect(ref, 20, 20) color.setAlpha(150 - i**0.5 * 50.0) painter.setPen(color) painter.drawPath(i_path) # 圆角 painter_rect = QPainter(self) painter_rect.setRenderHint(QPainter.Antialiasing) # 抗锯齿 color_bg = QColor(170, 248, 248, 240) # 设置背警色 painter_rect.setBrush(color_bg) painter_rect.setPen(Qt.transparent) self._rect = self.rect() self._rect.setLeft(15) self._rect.setTop(15) self._rect.setWidth(self._rect.width() - 15) self._rect.setHeight(self._rect.height() - 15) painter_rect.drawRoundedRect(self._rect, 15, 15)
def __init__(self, parent): super(QNEBlock, self).__init__(parent) path = QPainterPath() path.addRoundedRect(-50, -15, 100, 30, 5, 5) #path.addRoundedRect(-50, -15, 100, 30, 5, 5); self.kmxNodeBlock = kmxNodeBlock() self.nodeColor = Qt.green self.nodeTextColor = Qt.blue self.nodeSelectedColor = Qt.yellow self.nodeSelectedTextColor = Qt.blue self.setPath(path) self.setPen(QPen(Qt.darkGreen)) self.setBrush(self.nodeColor) self.setOpacity(0.9) self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsSelectable) self.setFlag(QGraphicsItem.ItemDoesntPropagateOpacityToChildren) self.horzMargin = 60 self.vertMargin = 25 self.width = self.horzMargin self.height = self.vertMargin
def paintEvent(self, event): super(BubbleLabel, self).paintEvent(event) painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) # 抗锯齿 rectPath = QPainterPath() # 圆角矩形 triPath = QPainterPath() # 底部三角形 height = self.height() - 8 # 往上偏移8 rectPath.addRoundedRect(QRectF(0, 0, self.width(), height), 5, 5) x = self.width() / 5 * 4 triPath.moveTo(x, height) # 移动到底部横线4/5处 # 画三角形 triPath.lineTo(x + 6, height + 8) triPath.lineTo(x + 12, height) rectPath.addPath(triPath) # 添加三角形到之前的矩形上 # 边框画笔 painter.setPen( QPen(self.BorderColor, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) # 背景画刷 painter.setBrush(self.BackgroundColor) # 绘制形状 painter.drawPath(rectPath) # 三角形底边绘制一条线保证颜色与背景一样 painter.setPen( QPen(self.BackgroundColor, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) painter.drawLine(x, height, x + 12, height)
def paintEvent(self, event): super().paintEvent(event) painter = QPainter(self) width = self.width() height = self.height() path = QPainterPath() path.addRoundedRect(2, 0, width - 4, height, 5, 5) # taskBgColor = monthcalendar.get_task_bgcolor( self.task ) selected = self.isSelected() taskBgColor = get_task_bgcolor(self.task, selected) painter.fillPath(path, taskBgColor) pathPen = QPen(QColor("black")) pathPen.setWidth(2) painter.strokePath(path, pathPen) pen = painter.pen() pen.setColor(QColor("black")) painter.setPen(pen) if height < 32: painter.drawText( 6, 0, width - 12, height, Qt.TextSingleLine | Qt.AlignVCenter | Qt.AlignLeft, self.task.title) else: painter.drawText( 6, 0, width - 12, 32, Qt.TextSingleLine | Qt.AlignVCenter | Qt.AlignLeft, self.task.title)
def toPdf(self, image): printer = QPrinter() printer.setPaperSize(QSizeF(210, 297), QPrinter.Millimeter) printer.setResolution(600) printer.setOutputFormat(QPrinter.PdfFormat) printer.setOutputFileName(self.get_path_to_revealer_file('.pdf')) printer.setPageMargins(0, 0, 0, 0, 6) painter = QPainter() painter.begin(printer) delta_h = round(image.width() / self.abstand_v) delta_v = round(image.height() / self.abstand_h) size_h = 2028 + ((int(self.calibration_h) * 2028 / (2028 - (delta_h * 2) + int(self.calibration_h))) / 2) size_v = 1284 + ((int(self.calibration_v) * 1284 / (1284 - (delta_v * 2) + int(self.calibration_v))) / 2) image = image.scaled(size_h, size_v) painter.drawImage(553, 533, image) wpath = QPainterPath() wpath.addRoundedRect(QRectF(553, 533, size_h, size_v), 19, 19) painter.setPen(QPen(Qt.black, 1)) painter.drawPath(wpath) painter.end()
def paint(self, painter, option, widget): shape = QPainterPath() shape.addRoundedRect(self.rect(), self._roundness, self._roundness) painter.setPen(self._shapePen) painter.setBrush(self._brush) painter.drawPath(shape)
def painterPath(self): """ Returns the current shape as QPainterPath (used for collision detection). :rtype: QPainterPath """ path = QPainterPath() path.addRoundedRect(self.polygon, 8, 8) return path
def shape(self): """ Returns the shape of this item as a QPainterPath in local coordinates. :rtype: QPainterPath """ path = QPainterPath() path.addRoundedRect(self.polygon, 8, 8) return path
def resizeEvent(self, event): self.resize(self.sizeHint()) path = QPainterPath() radius = 10 path.addRoundedRect(QRectF(self.rect()), radius, radius) mask = QRegion(path.toFillPolygon(QTransform()).toPolygon()) self.setMask(mask) QDialog.resizeEvent(self, event)
def fill_rect(self, rect, color, radius=0): if radius == 0: self.painter.fillRect(rect.to_qt(), color.to_qt()) return path = QPainterPath() path.addRoundedRect(rect.to_qt_f(), radius, radius) self.painter.fillPath(path, color.to_qt())
def paintEvent(self, ev): path = QPainterPath() painter = QPainter(self) painter.setPen(QPen(QColor(255, 0, 0, 127), 6)) painter.setRenderHint(QPainter.Antialiasing) path.addRoundedRect(self.edge, 15, 15) painter.drawPath(path) painter.fillPath(path, self.bgColor)
def paint(self, painter, options, widget): # drawing and filling a rounded rect painter.setRenderHint(QPainter.Antialiasing) path = QPainterPath() path.addRoundedRect(self.rect(), 2, 2) painter.fillPath(path, QColor('white')) painter.drawPath(path) painter.setFont(QFont('Inconsolata', 9)) painter.drawText(self.rect(), Qt.AlignCenter, str(self.value))
def paintEvent(self, event): # create round rect super(NotificationItem, self).paintEvent(event) painter = QPainter(self) path = QPainterPath() path.addRoundedRect(QRectF(self.rect()), 6, 6) # background color setting painter.fillPath(path, self.bg_color)
def set_shape(self, width, height): ''' Compute the polygon to fit in width, height ''' path = QPainterPath() path.addRoundedRect(0, 0, width, height, height / 2, height / 2) path.moveTo(min(width / 2, height / 2), 0) path.lineTo(min(width / 2, height / 2), height) path.moveTo(max(width / 2, width - height / 2), 0) path.lineTo(max(width / 2, width - height / 2), height) self.setPath(path) super(Start, self).set_shape(width, height)
def set_shape(self, width, height): ''' Compute the polygon to fit in width, height ''' path = QPainterPath() path.addRoundedRect(0, 0, width, height, height / 4, height) if self.nested_scene and self.is_composite(): # Distinguish composite states with dash line self.setPen(QPen(Qt.DashLine)) else: self.setPen(QPen(Qt.SolidLine)) self.setPath(path) super(State, self).set_shape(width, height)
def painterPath(self): i_g = self._item_group # the childrenBoundingRect is necessary to get this to work rect = self.mapRectFromItem(i_g, i_g.childrenBoundingRect()) radius = self._RADIUS path = QPainterPath() path.addRoundedRect(rect, radius, radius) path.moveTo(rect.right(),\ rect.center().y()) path.lineTo(rect.right() + radius / 2,\ rect.center().y()) return path
def __init__(self, parent): super(QNEBlock, self).__init__(parent) path = QPainterPath() path.addRoundedRect(-50, -15, 100, 30, 5, 5); self.setPath(path) self.setPen(QPen(Qt.darkGreen)) self.setBrush(Qt.green) self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsSelectable) self.horzMargin = 20 self.vertMargin = 5 self.width = self.horzMargin self.height = self.vertMargin
def getRoundedRectPath(self, i, yTranslation, side): path = QPainterPath(); path.setFillRule(Qt.WindingFill); path.addRoundedRect(self.ioList[i][0], self.ioList[i][1] + yTranslation, self.ioWidth, self.ioHeight, 2, 2) #Remove rounded edges on left or right side if side == 'left': path.addRect(self.ioList[i][0], self.ioList[i][1] + yTranslation, 2, 2) path.addRect(self.ioList[i][0], self.ioList[i][1] + yTranslation + self.ioHeight - 2, 2, 2) else: path.addRect(self.ioList[i][0] + self.ioWidth - 2, self.ioList[i][1] + yTranslation, 2, 2) path.addRect(self.ioList[i][0] + self.ioWidth - 2, self.ioList[i][1] + yTranslation + self.ioHeight - 2, 2, 2) return path
def paintEvent(self, event): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) self._optionsRects = {} w, h = self.width(), self.height() metrics = self.fontMetrics() hphp = 2 * _hPad painter.save() path = QPainterPath() path.addRoundedRect(.5, .5, w - 1, h - 1, 4, 4) painter.fillPath(path, QColor(250, 250, 250)) x = 0 linePath = QPainterPath() for text in self._options[:-1]: x += hphp + metrics.width(text) linePath.moveTo(x, 0) linePath.lineTo(x, h) pen = painter.pen() pen.setColor(QColor(218, 218, 218)) pen.setWidth(0) painter.setPen(pen) painter.drawPath(path) painter.setRenderHint(QPainter.Antialiasing, False) painter.drawPath(linePath) painter.restore() painter.translate(_hPad, _vPad + metrics.ascent()) left = 0 for index, text in enumerate(self._options): if index in self._selection: color = QColor(20, 146, 230) else: color = QColor(63, 63, 63) painter.setPen(color) painter.drawText(0, 0, text) textWidth = metrics.width(text) rectWidth = textWidth + hphp rect = (left, 0, rectWidth, h) self._optionsRects[index] = rect painter.translate(rectWidth, 0) left += rectWidth
def create_rounded_image(pixmap): color = QColor(0, 0, 0, 0) pix = QPixmap(QSize(pixmap.width(), pixmap.height())) pix.fill(color) rect = QRectF(0.0, 0.0, pixmap.width(), pixmap.height()) painter = QPainter() painter.begin(pix) painter.setRenderHints(QPainter.Antialiasing, True) path = QPainterPath() path.addRoundedRect(rect, pixmap.width() / 2, pixmap.height() / 2) painter.drawPath(path) brush = QtGui.QBrush() brush.setTexture(pixmap) painter.fillPath(path, brush) painter.end() return pix
def pixmap(self, mode=QIcon.Normal, state=QIcon.Off): pixmap = self.icon().pixmap(self.iconSize(), mode, state) if pixmap.isNull(): return pixmap size = max(pixmap.width(), pixmap.height()) offset_x = (size - pixmap.width()) / 2 offset_y = (size - pixmap.height()) / 2 new_pixmap = QPixmap(size, size) new_pixmap.fill(Qt.transparent) path = QPainterPath() path.addRoundedRect(0, 0, size, size, 3.7, 3.7) painter = QPainter(new_pixmap) painter.setRenderHint(QPainter.Antialiasing, True) painter.setCompositionMode(QPainter.CompositionMode_SourceOver) painter.setClipPath(path) painter.drawPixmap(offset_x, offset_y, pixmap) painter.end() return new_pixmap
def paintEvent(self, e): w=self.width() h=self.height() if self.enable_pulse==True: l=(w-3)*0.2 bar_start=((w-3)-l)*self.value else: l=(w-3)*self.value bar_start=0 qp = QPainter() qp.begin(self) color = QColor(0, 0, 0) color.setNamedColor('#d4d4d4') qp.setBrush(color) path=QPainterPath() path.addRoundedRect(QRectF(0, 0, w, h), 0, 0) qp.fillPath(path,QColor(206 , 206, 206)); path=QPainterPath() path.addRoundedRect(QRectF(bar_start, 3, l, h-6), 5, 5) qp.fillPath(path,QColor(71 , 142, 216)); #path.addPolygon(QPolygonF([QPoint(0,0), QPoint(10,0), QPoint(10,10), QPoint(10,0)])); #qp.setBrush(QColor(71 , 142, 216)) #path.addPolygon(QPolygonF([QPoint(0,0), QPoint(50,0), QPoint(40,10), QPoint(10,0)])) #qp.setBrush(QColor(71 , 142, 216)) #qp.setBrush(QColor(206 , 207, 206)) qp.end()
def toPdf(self, image): printer = QPrinter() printer.setPaperSize(QSizeF(210, 297), QPrinter.Millimeter) printer.setResolution(600) printer.setOutputFormat(QPrinter.PdfFormat) printer.setOutputFileName(self.get_path_to_revealer_file('.pdf')) printer.setPageMargins(0,0,0,0,6) painter = QPainter() painter.begin(printer) delta_h = round(image.width()/self.abstand_v) delta_v = round(image.height()/self.abstand_h) size_h = 2028+((int(self.calibration_h)*2028/(2028-(delta_h*2)+int(self.calibration_h)))/2) size_v = 1284+((int(self.calibration_v)*1284/(1284-(delta_v*2)+int(self.calibration_v)))/2) image = image.scaled(size_h, size_v) painter.drawImage(553,533, image) wpath = QPainterPath() wpath.addRoundedRect(QRectF(553,533, size_h, size_v), 19, 19) painter.setPen(QPen(Qt.black, 1)) painter.drawPath(wpath) painter.end()
def paint(self, painter, option, index): assert isinstance(painter, QPainter) if index.data(Qt.UserRole+1): if app_constants.HIGH_QUALITY_THUMBS: painter.setRenderHint(QPainter.SmoothPixmapTransform) painter.setRenderHint(QPainter.Antialiasing) gallery = index.data(Qt.UserRole+1) title = gallery.title artist = gallery.artist title_color = app_constants.GRID_VIEW_TITLE_COLOR artist_color = app_constants.GRID_VIEW_ARTIST_COLOR label_color = app_constants.GRID_VIEW_LABEL_COLOR # Enable this to see the defining box #painter.drawRect(option.rect) # define font size if 20 > len(title) > 15: title_size = "font-size:{}px;".format(self.font_size) elif 30 > len(title) > 20: title_size = "font-size:{}px;".format(self.font_size-1) elif 40 > len(title) >= 30: title_size = "font-size:{}px;".format(self.font_size-2) elif 50 > len(title) >= 40: title_size = "font-size:{}px;".format(self.font_size-3) elif len(title) >= 50: title_size = "font-size:{}px;".format(self.font_size-4) else: title_size = "font-size:{}px;".format(self.font_size) if 30 > len(artist) > 20: artist_size = "font-size:{}px;".format(self.font_size) elif 40 > len(artist) >= 30: artist_size = "font-size:{}px;".format(self.font_size-1) elif len(artist) >= 40: artist_size = "font-size:{}px;".format(self.font_size-2) else: artist_size = "font-size:{}px;".format(self.font_size) #painter.setPen(QPen(Qt.NoPen)) #option.rect = option.rect.adjusted(11, 10, 0, 0) option.rect.setWidth(self.W) option.rect.setHeight(self.H) rec = option.rect.getRect() x = rec[0] y = rec[1] w = rec[2] h = rec[3] text_area = QTextDocument() text_area.setDefaultFont(option.font) text_area.setHtml(""" <head> <style> #area {{ display:flex; width:140px; height:10px }} #title {{ position:absolute; color: {4}; font-weight:bold; {0} }} #artist {{ position:absolute; color: {5}; top:20px; right:0; {1} }} </style> </head> <body> <div id="area"> <center> <div id="title">{2} </div> <div id="artist">{3} </div> </div> </center> </body> """.format(title_size, artist_size, title, artist, title_color, artist_color)) text_area.setTextWidth(w) #chapter_area = QTextDocument() #chapter_area.setDefaultFont(option.font) #chapter_area.setHtml(""" #<font color="black">{}</font> #""".format("chapter")) #chapter_area.setTextWidth(w) def center_img(width): new_x = x if width < w: diff = w - width offset = diff//2 new_x += offset return new_x # if we can't find a cached image pix_cache = QPixmapCache.find(self.key(gallery.profile)) if isinstance(pix_cache, QPixmap): self.image = pix_cache img_x = center_img(self.image.width()) if self.image.height() < self.image.width(): #to keep aspect ratio painter.drawPixmap(QPoint(img_x,y), self.image) else: painter.drawPixmap(QPoint(img_x,y), self.image) else: self.image = QPixmap(gallery.profile) img_x = center_img(self.image.width()) QPixmapCache.insert(self.key(gallery.profile), self.image) if self.image.height() < self.image.width(): #to keep aspect ratio painter.drawPixmap(QPoint(img_x,y), self.image) else: painter.drawPixmap(QPoint(img_x,y), self.image) # draw star if it's favorited if gallery.fav == 1: painter.drawPixmap(QPointF(x,y), QPixmap(app_constants.STAR_PATH)) if app_constants._REFRESH_EXTERNAL_VIEWER: if app_constants.USE_EXTERNAL_VIEWER: self.external_icon = self.file_icons.get_external_file_icon() else: self.external_icon = self.file_icons.get_default_file_icon() if gallery.state == self.G_DOWNLOAD: painter.save() dl_box = QRect(x, y, w, 20) painter.setBrush(QBrush(QColor(0,0,0,123))) painter.setPen(QColor('white')) painter.drawRect(dl_box) painter.drawText(dl_box, Qt.AlignCenter, 'Downloading...') painter.restore() else: if app_constants.DISPLAY_GALLERY_TYPE: self.type_icon = self.file_icons.get_file_icon(gallery.path) if self.type_icon and not self.type_icon.isNull(): self.type_icon.paint(painter, QRect(x+2, y+app_constants.THUMB_H_SIZE-16, 16, 16)) if app_constants.USE_EXTERNAL_PROG_ICO: if self.external_icon and not self.external_icon.isNull(): self.external_icon.paint(painter, QRect(x+w-30, y+app_constants.THUMB_H_SIZE-28, 28, 28)) def draw_text_label(lbl_h): #draw the label for text painter.save() painter.translate(x, y+app_constants.THUMB_H_SIZE) box_color = QBrush(QColor(label_color))#QColor(0,0,0,123)) painter.setBrush(box_color) rect = QRect(0, 0, w, lbl_h) #x, y, width, height painter.fillRect(rect, box_color) painter.restore() return rect if option.state & QStyle.State_MouseOver or\ option.state & QStyle.State_Selected: title_layout = self.text_layout(title, w, self.title_font, self.title_font_m) artist_layout = self.text_layout(artist, w, self.artist_font, self.artist_font_m) t_h = title_layout.boundingRect().height() a_h = artist_layout.boundingRect().height() if app_constants.GALLERY_FONT_ELIDE: lbl_rect = draw_text_label(min(t_h+a_h+3, app_constants.GRIDBOX_LBL_H)) else: lbl_rect = draw_text_label(app_constants.GRIDBOX_LBL_H) clipping = QRectF(x, y+app_constants.THUMB_H_SIZE, w, app_constants.GRIDBOX_LBL_H - 10) title_layout.draw(painter, QPointF(x, y+app_constants.THUMB_H_SIZE), clip=clipping) artist_layout.draw(painter, QPointF(x, y+app_constants.THUMB_H_SIZE+t_h), clip=clipping) #painter.fillRect(option.rect, QColor) else: if app_constants.GALLERY_FONT_ELIDE: lbl_rect = draw_text_label(self.text_label_h) else: lbl_rect = draw_text_label(app_constants.GRIDBOX_LBL_H) # draw text painter.save() alignment = QTextOption(Qt.AlignCenter) alignment.setUseDesignMetrics(True) title_rect = QRectF(0,0,w, self.title_font_m.height()) artist_rect = QRectF(0,self.artist_font_m.height(),w, self.artist_font_m.height()) painter.translate(x, y+app_constants.THUMB_H_SIZE) if app_constants.GALLERY_FONT_ELIDE: painter.setFont(self.title_font) painter.setPen(QColor(title_color)) painter.drawText(title_rect, self.title_font_m.elidedText(title, Qt.ElideRight, w-10), alignment) painter.setPen(QColor(artist_color)) painter.setFont(self.artist_font) alignment.setWrapMode(QTextOption.NoWrap) painter.drawText(artist_rect, self.title_font_m.elidedText(artist, Qt.ElideRight, w-10), alignment) else: text_area.setDefaultFont(QFont(self.font_name)) text_area.drawContents(painter) ##painter.resetTransform() painter.restore() if option.state & QStyle.State_Selected: painter.save() selected_rect = QRectF(x, y, w, lbl_rect.height()+app_constants.THUMB_H_SIZE) painter.setPen(Qt.NoPen) painter.setBrush(QBrush(QColor(164,164,164,120))) p_path = QPainterPath() p_path.setFillRule(Qt.WindingFill) p_path.addRoundedRect(selected_rect, 5,5) p_path.addRect(x,y, 20, 20) p_path.addRect(x+w-20,y, 20, 20) painter.drawPath(p_path.simplified()) #painter.fillRect(selected_rect, QColor(164,164,164,120)) painter.restore() #if option.state & QStyle.State_Selected: # painter.setPen(QPen(option.palette.highlightedText().color())) else: super().paint(painter, option, index)
def set_shape(self, width, height): ''' Compute the polygon to fit in width, height ''' path = QPainterPath() path.addRoundedRect(0, 0, width, height, height / 2, height / 2) self.setPath(path) super(Start, self).set_shape(width, height)
def paint(self, painter, option, index): assert isinstance(painter, QPainter) if index.data(Qt.UserRole+1): if app_constants.HIGH_QUALITY_THUMBS: painter.setRenderHint(QPainter.SmoothPixmapTransform) painter.setRenderHint(QPainter.Antialiasing) gallery = index.data(Qt.UserRole+1) title = gallery.title artist = gallery.artist title_color = app_constants.GRID_VIEW_TITLE_COLOR artist_color = app_constants.GRID_VIEW_ARTIST_COLOR label_color = app_constants.GRID_VIEW_LABEL_COLOR # Enable this to see the defining box #painter.drawRect(option.rect) # define font size if 20 > len(title) > 15: title_size = "font-size:{}px;".format(self.font_size) elif 30 > len(title) > 20: title_size = "font-size:{}px;".format(self.font_size-1) elif 40 > len(title) >= 30: title_size = "font-size:{}px;".format(self.font_size-2) elif 50 > len(title) >= 40: title_size = "font-size:{}px;".format(self.font_size-3) elif len(title) >= 50: title_size = "font-size:{}px;".format(self.font_size-4) else: title_size = "font-size:{}px;".format(self.font_size) if 30 > len(artist) > 20: artist_size = "font-size:{}px;".format(self.font_size) elif 40 > len(artist) >= 30: artist_size = "font-size:{}px;".format(self.font_size-1) elif len(artist) >= 40: artist_size = "font-size:{}px;".format(self.font_size-2) else: artist_size = "font-size:{}px;".format(self.font_size) #painter.setPen(QPen(Qt.NoPen)) #option.rect = option.rect.adjusted(11, 10, 0, 0) option.rect.setWidth(self.W) option.rect.setHeight(self.H) rec = option.rect.getRect() x = rec[0] y = rec[1] w = rec[2] h = rec[3] text_area = QTextDocument() text_area.setDefaultFont(option.font) text_area.setHtml(""" <head> <style> #area {{ display:flex; width:{6}px; height:{7}px }} #title {{ position:absolute; color: {4}; font-weight:bold; {0} }} #artist {{ position:absolute; color: {5}; top:20px; right:0; {1} }} </style> </head> <body> <div id="area"> <center> <div id="title">{2} </div> <div id="artist">{3} </div> </div> </center> </body> """.format(title_size, artist_size, title, artist, title_color, artist_color, 130+app_constants.SIZE_FACTOR, 1+app_constants.SIZE_FACTOR)) text_area.setTextWidth(w) #chapter_area = QTextDocument() #chapter_area.setDefaultFont(option.font) #chapter_area.setHtml(""" #<font color="black">{}</font> #""".format("chapter")) #chapter_area.setTextWidth(w) def center_img(width): new_x = x if width < w: diff = w - width offset = diff//2 new_x += offset return new_x def img_too_big(start_x): txt_layout = misc.text_layout("Image is too big!", w, self.title_font, self.title_font_m) clipping = QRectF(x, y+h//4, w, app_constants.GRIDBOX_LBL_H - 10) txt_layout.draw(painter, QPointF(x, y+h//4), clip=clipping) # if we can't find a cached image pix_cache = QPixmapCache.find(self.key(gallery.profile)) if isinstance(pix_cache, QPixmap): self.image = pix_cache img_x = center_img(self.image.width()) if self.image.width() > w or self.image.height() > h: img_too_big(img_x) else: if self.image.height() < self.image.width(): #to keep aspect ratio painter.drawPixmap(QPoint(img_x,y), self.image) else: painter.drawPixmap(QPoint(img_x,y), self.image) else: self.image = QPixmap(gallery.profile) img_x = center_img(self.image.width()) QPixmapCache.insert(self.key(gallery.profile), self.image) if self.image.width() > w or self.image.height() > h: img_too_big(img_x) else: if self.image.height() < self.image.width(): #to keep aspect ratio painter.drawPixmap(QPoint(img_x,y), self.image) else: painter.drawPixmap(QPoint(img_x,y), self.image) # draw ribbon type painter.save() painter.setPen(Qt.NoPen) if app_constants.DISPLAY_GALLERY_RIBBON: type_ribbon_w = type_ribbon_l = w*0.11 rib_top_1 = QPointF(x+w-type_ribbon_l-type_ribbon_w, y) rib_top_2 = QPointF(x+w-type_ribbon_l, y) rib_side_1 = QPointF(x+w, y+type_ribbon_l) rib_side_2 = QPointF(x+w, y+type_ribbon_l+type_ribbon_w) ribbon_polygon = QPolygonF([rib_top_1, rib_top_2, rib_side_1, rib_side_2]) ribbon_path = QPainterPath() ribbon_path.setFillRule(Qt.WindingFill) ribbon_path.addPolygon(ribbon_polygon) ribbon_path.closeSubpath() painter.setBrush(QBrush(QColor(self._ribbon_color(gallery.type)))) painter.drawPath(ribbon_path) # draw if favourited if gallery.fav == 1: star_ribbon_w = star_ribbon_l = w*0.08 rib_top_1 = QPointF(x+star_ribbon_l, y) rib_side_1 = QPointF(x, y+star_ribbon_l) rib_top_2 = QPointF(x+star_ribbon_l+star_ribbon_w, y) rib_side_2 = QPointF(x, y+star_ribbon_l+star_ribbon_w) rib_star_mid_1 = QPointF((rib_top_1.x()+rib_side_1.x())/2, (rib_top_1.y()+rib_side_1.y())/2) rib_star_factor = star_ribbon_l/4 rib_star_p1_1 = rib_star_mid_1 + QPointF(rib_star_factor, -rib_star_factor) rib_star_p1_2 = rib_star_p1_1 + QPointF(-rib_star_factor, -rib_star_factor) rib_star_p1_3 = rib_star_mid_1 + QPointF(-rib_star_factor, rib_star_factor) rib_star_p1_4 = rib_star_p1_3 + QPointF(-rib_star_factor, -rib_star_factor) crown_1 = QPolygonF([rib_star_p1_1, rib_star_p1_2, rib_star_mid_1, rib_star_p1_4, rib_star_p1_3]) painter.setBrush(QBrush(QColor("yellow"))) painter.drawPolygon(crown_1) ribbon_polygon = QPolygonF([rib_top_1, rib_side_1, rib_side_2, rib_top_2]) ribbon_path = QPainterPath() ribbon_path.setFillRule(Qt.WindingFill) ribbon_path.addPolygon(ribbon_polygon) ribbon_path.closeSubpath() painter.drawPath(ribbon_path) #painter.setPen(QColor("#d35400")) #painter.drawPolyline(rib_top_1, rib_star_p1_1, rib_star_p1_2, rib_star_mid_1, rib_star_p1_4, rib_star_p1_3, rib_side_1) #painter.drawLine(rib_top_1, rib_top_2) #painter.drawLine(rib_top_2, rib_side_2) #painter.drawLine(rib_side_1, rib_side_2) painter.restore() if app_constants._REFRESH_EXTERNAL_VIEWER: if app_constants.USE_EXTERNAL_VIEWER: self.external_icon = self.file_icons.get_external_file_icon() else: self.external_icon = self.file_icons.get_default_file_icon() if gallery.state == self.G_DOWNLOAD: painter.save() dl_box = QRect(x, y, w, 20) painter.setBrush(QBrush(QColor(0,0,0,123))) painter.setPen(QColor('white')) painter.drawRect(dl_box) painter.drawText(dl_box, Qt.AlignCenter, 'Downloading...') painter.restore() else: if app_constants.DISPLAY_GALLERY_TYPE: self.type_icon = self.file_icons.get_file_icon(gallery.path) if self.type_icon and not self.type_icon.isNull(): self.type_icon.paint(painter, QRect(x+2, y+app_constants.THUMB_H_SIZE-16, 16, 16)) if app_constants.USE_EXTERNAL_PROG_ICO: if self.external_icon and not self.external_icon.isNull(): self.external_icon.paint(painter, QRect(x+w-30, y+app_constants.THUMB_H_SIZE-28, 28, 28)) def draw_text_label(lbl_h): #draw the label for text painter.save() painter.translate(x, y+app_constants.THUMB_H_SIZE) box_color = QBrush(QColor(label_color))#QColor(0,0,0,123)) painter.setBrush(box_color) rect = QRect(0, 0, w, lbl_h) #x, y, width, height painter.fillRect(rect, box_color) painter.restore() return rect if option.state & QStyle.State_MouseOver or\ option.state & QStyle.State_Selected: title_layout = misc.text_layout(title, w, self.title_font, self.title_font_m) artist_layout = misc.text_layout(artist, w, self.artist_font, self.artist_font_m) t_h = title_layout.boundingRect().height() a_h = artist_layout.boundingRect().height() if app_constants.GALLERY_FONT_ELIDE: lbl_rect = draw_text_label(min(t_h+a_h+3, app_constants.GRIDBOX_LBL_H)) else: lbl_rect = draw_text_label(app_constants.GRIDBOX_LBL_H) clipping = QRectF(x, y+app_constants.THUMB_H_SIZE, w, app_constants.GRIDBOX_LBL_H - 10) painter.setPen(QColor(title_color)) title_layout.draw(painter, QPointF(x, y+app_constants.THUMB_H_SIZE), clip=clipping) painter.setPen(QColor(artist_color)) artist_layout.draw(painter, QPointF(x, y+app_constants.THUMB_H_SIZE+t_h), clip=clipping) #painter.fillRect(option.rect, QColor) else: if app_constants.GALLERY_FONT_ELIDE: lbl_rect = draw_text_label(self.text_label_h) else: lbl_rect = draw_text_label(app_constants.GRIDBOX_LBL_H) # draw text painter.save() alignment = QTextOption(Qt.AlignCenter) alignment.setUseDesignMetrics(True) title_rect = QRectF(0,0,w, self.title_font_m.height()) artist_rect = QRectF(0,self.artist_font_m.height(),w, self.artist_font_m.height()) painter.translate(x, y+app_constants.THUMB_H_SIZE) if app_constants.GALLERY_FONT_ELIDE: painter.setFont(self.title_font) painter.setPen(QColor(title_color)) painter.drawText(title_rect, self.title_font_m.elidedText(title, Qt.ElideRight, w-10), alignment) painter.setPen(QColor(artist_color)) painter.setFont(self.artist_font) alignment.setWrapMode(QTextOption.NoWrap) painter.drawText(artist_rect, self.title_font_m.elidedText(artist, Qt.ElideRight, w-10), alignment) else: text_area.setDefaultFont(QFont(self.font_name)) text_area.drawContents(painter) ##painter.resetTransform() painter.restore() if option.state & QStyle.State_Selected: painter.save() selected_rect = QRectF(x, y, w, lbl_rect.height()+app_constants.THUMB_H_SIZE) painter.setPen(Qt.NoPen) painter.setBrush(QBrush(QColor(164,164,164,120))) painter.drawRoundedRect(selected_rect, 5, 5) #painter.fillRect(selected_rect, QColor(164,164,164,120)) painter.restore() if gallery.dead_link: painter.save() selected_rect = QRectF(x, y, w, lbl_rect.height()+app_constants.THUMB_H_SIZE) painter.setPen(Qt.NoPen) painter.setBrush(QBrush(QColor(255,0,0,120))) p_path = QPainterPath() p_path.setFillRule(Qt.WindingFill) p_path.addRoundedRect(selected_rect, 5,5) p_path.addRect(x,y, 20, 20) p_path.addRect(x+w-20,y, 20, 20) painter.drawPath(p_path.simplified()) painter.setPen(QColor("white")) txt_layout = misc.text_layout("Cannot find gallery source!", w, self.title_font, self.title_font_m) txt_layout.draw(painter, QPointF(x, y+h*0.3)) painter.restore() if app_constants.DEBUG: painter.save() painter.setBrush(QBrush(QColor("red"))) painter.setPen(QColor("white")) txt_l = self.title_font_m.width(str(gallery.id)) painter.drawRect(x, y+40, txt_l*2, self.title_font_m.height()) painter.drawText(x+1, y+51, str(gallery.id)) painter.restore() if option.state & QStyle.State_Selected: painter.setPen(QPen(option.palette.highlightedText().color())) else: super().paint(painter, option, index)