def paint(self, painter: QPainter, *_): painter.save() painter.setPen(pg.mkPen((255, 255, 100), width=1)) painter.setBrush(pg.mkBrush(255, 255, 0, 100)) if self.__selection_range is not None: painter.drawRect(self.selection_rect) painter.restore()
def paint(self, painter: QPainter, *_): painter.save() painter.setPen(pg.mkPen(QColor(Qt.black))) painter.setBrush(self.__violin_brush) painter.drawPath(self.__violin_path) if self.__show_rug_plot: data, density = self.__rug_plot_data painter.setPen(pg.mkPen(QColor(Qt.black), width=1)) for x, y in zip(density, data): if self.__orientation == Qt.Vertical: painter.drawLine(QPointF(-x, y), QPointF(x, y)) else: painter.drawLine(QPointF(y, -x), QPointF(y, x)) painter.restore()
def paintEvent(self, event): super().paintEvent(event) p = QPainter(self) p.setRenderHint(QPainter.Antialiasing) p.setBrush(self.indicator_color) p.save() p.setPen(Qt.NoPen) fm = QFontMetrics(self.font()) width = self.rect().width() height = fm.height() + 6 rect = QRectF(0, 0, width, height) p.drawRoundedRect(rect, 5, 5) p.restore() textstart = (width - fm.width(self.indicator_text)) / 2 p.drawText(textstart, height / 2 + 5, self.indicator_text)
def paint( self, painter: QPainter, option: QStyleOptionViewItem, index: QModelIndex ) -> None: opt = QStyleOptionViewItem(option) self.initStyleOption(opt, index) widget = option.widget style = QApplication.style() if widget is None else widget.style() self.__style = style text = opt.text opt.text = "" style.drawControl(QStyle.CE_ItemViewItem, opt, painter, widget) textrect = style.subElementRect( QStyle.SE_ItemViewItemText, opt, widget) ratio = self.barFillRatioData(index) if ratio is not None and 0. <= ratio <= 1.: color = self.barColorData(index) if color is None: color = self.color if not color.isValid(): color = opt.palette.color(QPalette.Foreground) rect = option.rect pw = self.penWidth hmargin = 3 + pw / 2 # + half pen width for the round line cap vmargin = 1 textoffset = pw + vmargin * 2 baseline = rect.bottom() - textoffset / 2 width = (rect.width() - 2 * hmargin) * ratio painter.save() painter.setRenderHint(QPainter.Antialiasing) pen = self.__pen pen.setColor(color) pen.setWidth(pw) painter.setPen(pen) line = self.__line left = rect.left() + hmargin line.setLine(left, baseline, left + width, baseline) painter.drawLine(line) painter.restore() textrect.adjust(0, 0, 0, -textoffset) opt.text = text self.drawViewItemText(style, painter, opt, textrect)
def paint(self, painter: QPainter, _, widget: Optional[QWidget]): painter.save() q0, q25, q75, q100 = self.__box_plot_data if self.__orientation == Qt.Vertical: quartile1 = QPointF(0, q0), QPointF(0, q100) quartile2 = QPointF(0, q25), QPointF(0, q75) else: quartile1 = QPointF(q0, 0), QPointF(q100, 0) quartile2 = QPointF(q25, 0), QPointF(q75, 0) factor = 1 if widget is None else widget.devicePixelRatio() painter.setPen(pg.mkPen(QColor(Qt.black), width=2 * factor)) painter.drawLine(*quartile1) painter.setPen(pg.mkPen(QColor(Qt.black), width=6 * factor)) painter.drawLine(*quartile2) painter.restore()
def picture_this_level(): # Create a QPicture drawing the contribution from this # level only. This is all regions where the contingency is # not empty and does not have a computed sub-contingency # (i.e. the node does not have a child in that cell). pic = QPicture() painter = QPainter(pic) ctng = node.contingencies colors = create_image(ctng, palette, scale=scale) x, y, w, h = node.brect N, M = ctng.shape[:2] # Nonzero contingency mask any_mask = Node_mask(node) if node.is_leaf: skip = itertools.repeat(False) else: # Skip all None children they were already painted. skip = (ch is not None for ch in node.children.flat) painter.save() painter.translate(x, y) painter.scale(w / node.nbins, h / node.nbins) indices = itertools.product(range(N), range(M)) for (i, j), skip, any_ in zip(indices, skip, any_mask.flat): if not skip and any_: painter.setBrush(QColor(*colors[i, j])) if shape == Rect: painter.drawRect(i, j, 1, 1) elif shape == Circle: painter.drawEllipse(i, j, 1, 1) elif shape == RoundRect: painter.drawRoundedRect(i, j, 1, 1, 25.0, 25.0, Qt.RelativeSize) painter.restore() painter.end() return pic
def innerShadowPixmap(color, size, pos, length=5): """ Args: color (QColor): shadow color size (QSize): size of pixmap pos (int): shadow position int flag, use bitwise operations 1 - top 2 - right 4 - bottom 8 - left length (int): length of cast shadow """ key = "InnerShadow " + \ color.name() + " " + \ str(size) + " " + \ str(pos) + " " + \ str(length) # get cached shadow if it exists finalShadow = QPixmapCache.find(key) if finalShadow: return finalShadow shadowTemplate = shadowTemplatePixmap(color, length) finalShadow = QPixmap(size) finalShadow.fill(Qt.transparent) shadowPainter = QPainter(finalShadow) shadowPainter.setCompositionMode(QPainter.CompositionMode_Darken) # top/bottom rect targetRect = QRect(0, 0, size.width(), length) # shadow on top if pos & 1: shadowPainter.drawPixmap(targetRect, shadowTemplate, shadowTemplate.rect()) # shadow on bottom if pos & 4: shadowPainter.save() shadowPainter.translate(QPointF(0, size.height())) shadowPainter.scale(1, -1) shadowPainter.drawPixmap(targetRect, shadowTemplate, shadowTemplate.rect()) shadowPainter.restore() # left/right rect targetRect = QRect(0, 0, size.height(), shadowTemplate.rect().height()) # shadow on the right if pos & 2: shadowPainter.save() shadowPainter.translate(QPointF(size.width(), 0)) shadowPainter.rotate(90) shadowPainter.drawPixmap(targetRect, shadowTemplate, shadowTemplate.rect()) shadowPainter.restore() # shadow on left if pos & 8: shadowPainter.save() shadowPainter.translate(0, size.height()) shadowPainter.rotate(-90) shadowPainter.drawPixmap(targetRect, shadowTemplate, shadowTemplate.rect()) shadowPainter.restore() shadowPainter.end() # cache shadow QPixmapCache.insert(key, finalShadow) return finalShadow
def __paintEventNoStyle(self): p = QPainter(self) opt = QStyleOptionToolButton() self.initStyleOption(opt) fm = QFontMetrics(opt.font) palette = opt.palette # highlight brush is used as the background for the icon and background # when the tab is expanded and as mouse hover color (lighter). brush_highlight = palette.highlight() if opt.state & QStyle.State_Sunken: # State 'down' pressed during a mouse press (slightly darker). background_brush = brush_darker(brush_highlight, 110) elif opt.state & QStyle.State_MouseOver: background_brush = brush_darker(brush_highlight, 95) elif opt.state & QStyle.State_On: background_brush = brush_highlight else: # The default button brush. background_brush = palette.button() rect = opt.rect icon_area_rect = QRect(rect) icon_area_rect.setRight(int(icon_area_rect.height() * 1.26)) text_rect = QRect(rect) text_rect.setLeft(icon_area_rect.right() + 10) # Background (TODO: Should the tab button have native # toolbutton shape, drawn using PE_PanelButtonTool or even # QToolBox tab shape) # Default outline pen pen = QPen(palette.color(QPalette.Mid)) p.save() p.setPen(Qt.NoPen) p.setBrush(QBrush(background_brush)) p.drawRect(rect) # Draw the background behind the icon if the background_brush # is different. if not opt.state & QStyle.State_On: p.setBrush(brush_highlight) p.drawRect(icon_area_rect) # Line between the icon and text p.setPen(pen) p.drawLine(icon_area_rect.topRight(), icon_area_rect.bottomRight()) if opt.state & QStyle.State_HasFocus: # Set the focus frame pen and draw the border pen = QPen(QColor(FOCUS_OUTLINE_COLOR)) p.setPen(pen) p.setBrush(Qt.NoBrush) # Adjust for pen rect = rect.adjusted(0, 0, -1, -1) p.drawRect(rect) else: p.setPen(pen) # Draw the top/bottom border if self.position == QStyleOptionToolBox.OnlyOneTab or \ self.position == QStyleOptionToolBox.Beginning or \ self.selected & \ QStyleOptionToolBox.PreviousIsSelected: p.drawLine(rect.topLeft(), rect.topRight()) p.drawLine(rect.bottomLeft(), rect.bottomRight()) p.restore() p.save() text = fm.elidedText(opt.text, Qt.ElideRight, text_rect.width()) p.setPen(QPen(palette.color(QPalette.ButtonText))) p.setFont(opt.font) p.drawText(text_rect, int(Qt.AlignVCenter | Qt.AlignLeft) | \ int(Qt.TextSingleLine), text) if not opt.icon.isNull(): if opt.state & QStyle.State_Enabled: mode = QIcon.Normal else: mode = QIcon.Disabled if opt.state & QStyle.State_On: state = QIcon.On else: state = QIcon.Off icon_area_rect = icon_area_rect icon_rect = QRect(QPoint(0, 0), opt.iconSize) icon_rect.moveCenter(icon_area_rect.center()) opt.icon.paint(p, icon_rect, Qt.AlignCenter, mode, state) p.restore()
def __paintEventNoStyle(self): p = QPainter(self) opt = QStyleOptionToolButton() self.initStyleOption(opt) fm = QFontMetrics(opt.font) palette = opt.palette # highlight brush is used as the background for the icon and background # when the tab is expanded and as mouse hover color (lighter). brush_highlight = palette.highlight() foregroundrole = QPalette.ButtonText if opt.state & QStyle.State_Sunken: # State 'down' pressed during a mouse press (slightly darker). background_brush = brush_darker(brush_highlight, 110) foregroundrole = QPalette.HighlightedText elif opt.state & QStyle.State_MouseOver: background_brush = brush_darker(brush_highlight, 95) foregroundrole = QPalette.HighlightedText elif opt.state & QStyle.State_On: background_brush = brush_highlight foregroundrole = QPalette.HighlightedText else: # The default button brush. background_brush = palette.button() rect = opt.rect icon_area_rect = QRect(rect) icon_area_rect.setRight(int(icon_area_rect.height() * 1.26)) text_rect = QRect(rect) text_rect.setLeft(icon_area_rect.right() + 10) # Background (TODO: Should the tab button have native # toolbutton shape, drawn using PE_PanelButtonTool or even # QToolBox tab shape) # Default outline pen pen = QPen(palette.color(QPalette.Mid)) p.save() p.setPen(Qt.NoPen) p.setBrush(QBrush(background_brush)) p.drawRect(rect) # Draw the background behind the icon if the background_brush # is different. if not opt.state & QStyle.State_On: p.setBrush(brush_highlight) p.drawRect(icon_area_rect) # Line between the icon and text p.setPen(pen) p.drawLine(icon_area_rect.topRight(), icon_area_rect.bottomRight()) if opt.state & QStyle.State_HasFocus: # Set the focus frame pen and draw the border pen = QPen(QColor(FOCUS_OUTLINE_COLOR)) p.setPen(pen) p.setBrush(Qt.NoBrush) # Adjust for pen rect = rect.adjusted(0, 0, -1, -1) p.drawRect(rect) else: p.setPen(pen) # Draw the top/bottom border if self.position == QStyleOptionToolBox.OnlyOneTab or \ self.position == QStyleOptionToolBox.Beginning or \ self.selected & \ QStyleOptionToolBox.PreviousIsSelected: p.drawLine(rect.topLeft(), rect.topRight()) p.drawLine(rect.bottomLeft(), rect.bottomRight()) p.restore() p.save() text = fm.elidedText(opt.text, Qt.ElideRight, text_rect.width()) p.setPen(QPen(palette.color(foregroundrole))) p.setFont(opt.font) p.drawText(text_rect, int(Qt.AlignVCenter | Qt.AlignLeft) | \ int(Qt.TextSingleLine), text) if not opt.icon.isNull(): if opt.state & QStyle.State_Enabled: mode = QIcon.Normal else: mode = QIcon.Disabled if opt.state & QStyle.State_On: state = QIcon.On else: state = QIcon.Off icon_area_rect = icon_area_rect icon_rect = QRect(QPoint(0, 0), opt.iconSize) icon_rect.moveCenter(icon_area_rect.center()) opt.icon.paint(p, icon_rect, Qt.AlignCenter, mode, state) p.restore()
def paint(self, painter: QPainter, *_): painter.save() painter.setPen(pg.mkPen((255, 255, 0), width=1)) painter.setBrush(pg.mkBrush(255, 255, 0, 100)) painter.drawRect(self.__rect) painter.restore()