def paintEvent(self, _): # pragma: no cover """Override to apply "background-color" property of QWidget""" opt = QStyleOption() opt.initFrom(self) painter = QPainter(self) self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
def paintEvent(self, ev): shown = self.button.isChecked() ls = self.fm.lineSpacing() painter = QPainter(self) if self.mouse_over: tool = QStyleOption() tool.rect = self.rect() tool.state = QStyle.State_Raised | QStyle.State_Active | QStyle.State_MouseOver s = self.style() s.drawPrimitive(QStyle.PE_PanelButtonTool, tool, painter, self) painter.drawText( 0, 0, self.width(), ls, Qt.AlignCenter | Qt.TextSingleLine, self.text) text = _('Hide') if shown else _('Show') f = self.font() f.setBold(True) painter.setFont(f) painter.drawText( 0, self.height() - ls, self.width(), ls, Qt.AlignCenter | Qt.TextSingleLine, text) x = (self.width() - ICON_SZ) // 2 y = ls + (self.height() - ICON_SZ - 2 * ls) // 2 pmap = self.bright_icon if shown else self.dull_icon painter.drawPixmap(x, y, pmap) painter.end()
def paintEvent(self, _): """Override paintEvent to paint background""" opt = QStyleOption() opt.initFrom(self) painter = QPainter(self) self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
def paintEvent(self, ev): if self.mouse_over: p = QPainter(self) tool = QStyleOption() tool.rect = self.rect() tool.state = QStyle.State_Raised | QStyle.State_Active | QStyle.State_MouseOver s = self.style() s.drawPrimitive(QStyle.PE_PanelButtonTool, tool, p, self) p.end() return QLabel.paintEvent(self, ev)
def paintEvent(self, ev): if self.mouse_over: p = QPainter(self) tool = QStyleOption() tool.rect = self.rect() tool.state = QStyle.StateFlag.State_Raised | QStyle.StateFlag.State_Active | QStyle.StateFlag.State_MouseOver s = self.style() s.drawPrimitive(QStyle.PrimitiveElement.PE_PanelButtonTool, tool, p, self) p.end() QWidget.paintEvent(self, ev)
def setToolbarButtonLook(self, enable): if enable: self._options |= self._ToolBarLookOption opt = QStyleOption() opt.initFrom(self) size = self.style().pixelMetric(QStyle.PM_ToolBarIconSize, opt, self) self.setIconSize(QSize(size, size)) else: self._options &= ~self._ToolBarLookOption self.setProperty('toolbar-look', enable) self.style().unpolish(self) self.style().polish(self)
def paintEvent(self, ev): shown = self.button.isChecked() ls = self.fm.lineSpacing() painter = QPainter(self) if self.mouse_over: tool = QStyleOption() tool.rect = self.rect() tool.state = QStyle.State_Raised | QStyle.State_Active | QStyle.State_MouseOver s = self.style() s.drawPrimitive(QStyle.PE_PanelButtonTool, tool, painter, self) painter.drawText(0, 0, self.width(), ls, Qt.AlignCenter | Qt.TextSingleLine, self.text) text = _('Hide') if shown else _('Show') f = self.font() f.setBold(True) painter.setFont(f) painter.drawText(0, self.height() - ls, self.width(), ls, Qt.AlignCenter | Qt.TextSingleLine, text) x = (self.width() - ICON_SZ) // 2 y = ls + (self.height() - ICON_SZ - 2 * ls) // 2 pmap = self.bright_icon if shown else self.dull_icon painter.drawPixmap(x, y, pmap) painter.end()
def paintEvent(self, event): opt = QStyleOption() opt.initFrom(self) painter = QPainter(self) self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
def paintEvent(self, event): ''' @param: event QPaintEvent ''' p = QPainter(self) # Just draw separator if self._bookmark.isSeparator(): opt = QStyleOption() opt.initFrom(self) opt.state |= QStyle.State_Horizontal self.style().drawPrimitive(QStyle.PE_IndicatorToolBarSeparator, opt, p) return option = QStyleOptionButton() self.initStyleOption(option) # We are manually drawing the arrow option.features &= ~QStyleOptionButton.HasMenu # Draw button base (only under mouse, this is autoraise button) if self.isDown() or self.hitButton(self.mapFromGlobal(QCursor.pos())): option.state |= QStyle.State_AutoRaise | QStyle.State_Raised self.style().drawPrimitive(QStyle.PE_PanelButtonTool, option, p, self) if self.isDown(): shiftX = self.style().pixelMetric(QStyle.PM_ButtonShiftHorizontal, option, self) shiftY = self.style().pixelMetric(QStyle.PM_ButtonShiftVertical, option, self) else: shiftX = 0 shiftY = 0 height = option.rect.height() center = height / 2 + option.rect.top() + shiftY iconSize = 16 iconYPos = center - iconSize / 2 leftPosition = self.PADDING + shiftX rightPosition = option.rect.right() - self.PADDING # Draw icon if not self._showOnlyText: iconRect = QRect(leftPosition, iconYPos, iconSize, iconSize) p.drawPixmap( QStyle.visualRect(option.direction, option.rect, iconRect), self._bookmark.icon().pixmap(iconSize)) leftPosition = iconRect.right() + self.PADDING # Draw menu arrow if not self._showOnlyIcon and self.menu(): arrowSize = 8 opt = QStyleOption() opt.initFrom(self) rect = QRect(rightPosition - 8, center - arrowSize / 2, arrowSize, arrowSize) opt.rect = QStyle.visualRect(option.direction, option.rect, rect) opt.state &= ~QStyle.State_MouseOver self.style().drawPrimitive(QStyle.PE_IndicatorArrowDown, opt, p, self) rightPosition = rect.left() - self.PADDING # Draw text if not self._showOnlyIcon: textWidth = rightPosition - leftPosition textYPos = center - self.fontMetrics().height() / 2 txt = self.fontMetrics().elidedText(self._bookmark.title(), Qt.ElideRight, textWidth) textRect = QRect(leftPosition, textYPos, textWidth, self.fontMetrics().height()) self.style().drawItemText( p, QStyle.visualRect(option.direction, option.rect, textRect), Qt.TextSingleLine | Qt.AlignCenter, option.palette, True, txt)
def paintEvent(self, event): opt = QStyleOption() opt.initFrom(self) painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)