Example #1
0
 def paintEvent(self, ev):
     shown = self.button.isChecked()
     ls = self.fm.lineSpacing()
     painter = QStylePainter(self)
     if self.mouse_over:
         tool = QStyleOption()
         tool.initFrom(self)
         tool.rect = self.rect()
         tool.state = QStyle.StateFlag.State_Raised | QStyle.StateFlag.State_Active | QStyle.StateFlag.State_MouseOver
         painter.drawPrimitive(QStyle.PrimitiveElement.PE_PanelButtonTool,
                               tool)
     painter.drawText(
         0, 0, self.width(), ls,
         Qt.AlignmentFlag.AlignCenter | Qt.TextFlag.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.AlignmentFlag.AlignCenter | Qt.TextFlag.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()
Example #2
0
 def paintEvent(self, ev):
     if self.mouse_over:
         p = QStylePainter(self)
         tool = QStyleOption()
         tool.initFrom(self)
         tool.rect = self.rect()
         tool.state = QStyle.StateFlag.State_Raised | QStyle.StateFlag.State_Active | QStyle.StateFlag.State_MouseOver
         p.drawPrimitive(QStyle.PrimitiveElement.PE_PanelButtonTool, tool)
         p.end()
     return QLabel.paintEvent(self, ev)
Example #3
0
 def style_option(self):
     opt = QStyleOption()
     opt.initFrom(self)
     opt.state |= QStyle.StateFlag.State_Horizontal
     return opt