def drawPrimitive(self, element, style_option: QStyleOption, painter: QPainter, widget=None): if element == QStyle.PE_FrameGroupBox: top_margin = max( self.pixelMetric(QStyle.PM_ExclusiveIndicatorHeight), style_option.fontMetrics.height()) + 3 frame_rect = style_option.rect.adjusted(0, top_margin, -1, -1) tab_frame_color = get_tab_frame_color(style_option.palette) painter.save() painter.setRenderHint(QPainter.Antialiasing) painter.translate(0.5, 0.5) painter.setPen( merged_colors(get_outline_color(style_option.palette), tab_frame_color)) painter.setBrush( merged_colors(style_option.palette.window().color(), tab_frame_color)) painter.drawRoundedRect(frame_rect, rounded_rect_radius(), rounded_rect_radius()) painter.restore() else: QProxyStyle.drawPrimitive(self, element, style_option, painter, widget)
def drawPrimitive(self, element, opt, painter, widget): if not self.__panel_widget(widget): return QProxyStyle.drawPrimitive(self, element, opt, painter, widget) if element == QStyle.PE_PanelButtonTool: flat = True pressed = (opt.state & STATE_SUNKEN or opt.state & STATE_ON) hovered = opt.state & STATE_ENABLED and opt.state & STATE_MOUSEOVER button_color = _COLORS['ToolButtonColor'] if not flat and widget.property("gradient"): button_color = QLinearGradient(opt.rect.topRight(), opt.rect.bottomRight()) button_color.setColorAt(0, QColor("#454545")) button_color.setColorAt(1, QColor("#191919")) if pressed: button_color = _COLORS['ToolButtonSelected'] elif hovered: if not flat and widget.property("gradient"): button_color.setColorAt(0, QColor("#555")) button_color.setColorAt(1, QColor("#191919")) else: button_color = _COLORS['ToolButtonHover'] if widget.property("border_bottom"): painter.setPen(_COLORS['Border']) painter.drawLine(opt.rect.bottomLeft(), opt.rect.bottomRight()) painter.fillRect(opt.rect.adjusted(2, 2, -2, -2), button_color) # elif not opt.state & STATE_ENABLED: # color = _PALETTE['ButtonDisabled'] # painter.fillRect(opt.rect, color) # TODO: keyboard focus change state # elif element == QStyle.PE_PanelButtonCommand: # Draw a flat push button # is_down = opt.state & STATE_SUNKEN or opt.state & STATE_ON # is_enabled = opt.state & STATE_ENABLED # is_hover = is_enabled and opt.state & STATE_MOUSEOVER # FIXME: has_focus state # FIXME: from theme # color = QColor("#444a58") # if is_down: # color = color.darker(130) # elif is_hover: # color = color.lighter(110) # painter.fillRect(opt.rect, color) elif element == QStyle.PE_PanelLineEdit: painter.save() # Fill background rect = opt.rect enabled = False if opt.state & STATE_ENABLED: enabled = True if not enabled: painter.setOpacity(0.55) painter.fillRect(rect, _COLORS['LineEditBackground']) has_focus = False if opt.state & QStyle.State_HasFocus: has_focus = True if enabled and (has_focus or opt.state & STATE_MOUSEOVER): # FIXME: color from theme # hover = QColor("#6a6ea9") # if has_focus: # alpha = 200 # else: # alpha = 55 # hover.setAlpha(alpha) # painter.setPen(QPen(hover, 2, Qt.SolidLine, # Qt.SquareCap, Qt.RoundJoin)) # painter.drawRect(rect.adjusted(0, 0, 0, 0)) pass painter.restore() elif element == QStyle.PE_IndicatorToolBarSeparator: rect = opt.rect painter.setPen(_COLORS['SeparatorColor']) border_rect = QRectF(rect).adjusted(0.5, 0.5, -0.5, -0.5) if opt.state & QStyle.State_Horizontal: border_rect.setWidth(1) painter.drawLine(border_rect.topRight() + QPointF(0, 3), border_rect.bottomRight() - QPointF(0, 3)) else: border_rect.setHeight(1) painter.drawLine(border_rect.topLeft() + QPointF(3, 0), border_rect.topRight() - QPointF(3, 0)) elif element == QStyle.PE_IndicatorToolBarHandle: # FIXME: draw a fancy handler QProxyStyle.drawPrimitive(self, element, opt, painter, widget) else: QProxyStyle.drawPrimitive(self, element, opt, painter, widget)