def paintSection(self, painter, rect, logicalIndex): # type: (QPainter, QRect, int) -> None """ Reimplemented from `QHeaderView`. """ # What follows is similar to QHeaderView::paintSection@Qt 6.0 if not rect.isValid(): return # pragma: no cover oldBO = painter.brushOrigin() opt = QStyleOptionHeader() opt.rect = rect self.initStyleOption(opt) oBrushButton = opt.palette.brush(QPalette.Button) oBrushWindow = opt.palette.brush(QPalette.Window) self.initStyleOptionForIndex(opt, logicalIndex) opt.rect = rect nBrushButton = opt.palette.brush(QPalette.Button) nBrushWindow = opt.palette.brush(QPalette.Window) if oBrushButton != nBrushButton or oBrushWindow != nBrushWindow: painter.setBrushOrigin(opt.rect.topLeft()) # draw the section self.style().drawControl(QStyle.CE_Header, opt, painter, self) painter.setBrushOrigin(oldBO)
def eventFilter(o, e): if (isinstance(o, QAbstractButton) and e.type() == QEvent.Paint): # paint by hand (borrowed from QTableCornerButton) btn = o opt = QStyleOptionHeader() opt.initFrom(btn) state = QStyle.State_None if btn.isEnabled(): state |= QStyle.State_Enabled if btn.isActiveWindow(): state |= QStyle.State_Active if btn.isDown(): state |= QStyle.State_Sunken opt.state = state opt.rect = btn.rect() opt.text = btn.text() opt.position = QStyleOptionHeader.OnlyOneSection painter = QStylePainter(btn) painter.drawControl(QStyle.CE_Header, opt) return True # eat event return False
def eventFilter(self, o, e): if (isinstance(o, QAbstractButton) and e.type() == QEvent.Paint): # paint by hand (borrowed from QTableCornerButton) btn = o opt = QStyleOptionHeader() opt.initFrom(btn) state = QStyle.State_None if btn.isEnabled(): state |= QStyle.State_Enabled if btn.isActiveWindow(): state |= QStyle.State_Active if btn.isDown(): state |= QStyle.State_Sunken opt.state = state opt.rect = btn.rect() opt.text = btn.text() opt.position = QStyleOptionHeader.OnlyOneSection painter = QStylePainter(btn) painter.drawControl(QStyle.CE_Header, opt) return True # eat event return False