def paint(self, painter, rect): panel = QStyleOptionFrame() panel.initFrom(self) panel.lineWidth = 2 panel.midLineWidth = 0 panel.rect = panel.rect.adjusted(*self._margins) style = self.style() style.drawPrimitive(QStyle.PE_Frame, panel, painter, self) rect = style.subElementRect(QStyle.SE_FrameContents, panel, self) painter.fillRect(rect, Qt.white) innerRect = rect.adjusted(2, 2, -2, -2) if self._color is not None: painter.fillRect(innerRect, self._color) else: pen = painter.pen() pen.setColor(strikeColor) pen.setWidthF(1.5) painter.setPen(pen) painter.setRenderHint(QStylePainter.Antialiasing) painter.setClipRect(innerRect) bL = innerRect.bottomLeft() bL.setY(bL.y() + .5) tR = innerRect.topRight() tR.setY(tR.y() + 1) painter.drawLine(bL, tR)
def paint(self, painter, rect): panel = QStyleOptionFrame() panel.initFrom(self) panel.lineWidth = 2 panel.midLineWidth = 0 panel.rect = panel.rect.adjusted(*self._margins) panel.state = panel.state | QStyle.State_Sunken self.style().drawPrimitive(QStyle.PE_Frame, panel, painter, self) r = self.style().subElementRect(QStyle.SE_FrameContents, panel, self) painter.fillRect(r, Qt.white) painter.fillRect(r.adjusted(2, 2, -2, -2), self._color)
def paintEvent(self, event): if not self.customStyle: return QGroupBox.paintEvent(self, event) p = QStylePainter(self) opt = QStyleOptionGroupBox() self.initStyleOption(opt) style = qApp.style() groupBox = opt # // Draw frame textRect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxLabel) checkBoxRect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxCheckBox) p.save() titleRect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxFrame) # r.setBottom(style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxContents).top()) titleRect.setHeight(textRect.height()) titleRect.moveTop(textRect.top()) p.setBrush(QBrush(QColor(Qt.blue).lighter(190))) p.setPen(Qt.NoPen) p.drawRoundedRect(titleRect, 10, 10) p.restore() if groupBox.subControls & QStyle.SC_GroupBoxFrame: frame = QStyleOptionFrame() # frame.operator=(groupBox) frame.state = groupBox.state frame.features = groupBox.features frame.lineWidth = groupBox.lineWidth frame.midLineWidth = groupBox.midLineWidth frame.rect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxFrame) p.save() region = QRegion(groupBox.rect) if groupBox.text: ltr = groupBox.direction == Qt.LeftToRight finalRect = QRect() if groupBox.subControls & QStyle.SC_GroupBoxCheckBox: finalRect = checkBoxRect.united(textRect) finalRect.adjust(-4 if ltr else 0, 0, 0 if ltr else 4, 0) else: finalRect = textRect region -= QRegion(finalRect) p.setClipRegion(region) style.drawPrimitive(style.PE_FrameGroupBox, frame, p) p.restore() # // Draw title if groupBox.subControls & QStyle.SC_GroupBoxLabel and groupBox.text: # textColor = QColor(groupBox.textColor) # if textColor.isValid(): # p.setPen(textColor) # alignment = int(groupBox.textAlignment) # if not style.styleHint(QStyle.SH_UnderlineShortcut, opt): # alignment |= Qt.TextHideMnemonic # style.drawItemText(p, textRect, Qt.TextShowMnemonic | Qt.AlignHCenter | alignment, # groupBox.palette, groupBox.state & style.State_Enabled, groupBox.text, # QPalette.NoRole if textColor.isValid() else QPalette.WindowText) p.save() topt = QTextOption(Qt.AlignHCenter | Qt.AlignVCenter) f = QFont() f.setBold(True) p.setFont(f) p.setPen(Qt.darkBlue) p.drawText(QRectF(titleRect), groupBox.text.replace("&", ""), topt) p.restore() if groupBox.state & style.State_HasFocus: fropt = QStyleOptionFocusRect() # fropt.operator=(groupBox) fropt.state = groupBox.state fropt.rect = textRect style.drawPrimitive(style.PE_FrameFocusRect, fropt, p)