(self, text, event)
Override paintEvent on widgets to also draw text.
Override paintEvent on widgets to also draw text.
Override paintEvent on widgets to also draw text .
def _paintEventOverride(self, text, event):
        """Override paintEvent on widgets to also draw text."""
        self._autoGridOriginalPaintEvent(event)
        text_flags = QtCore.Qt.AlignHCenter | QtCore.Qt.AlignBottom  | QtCore.Qt.TextWordWrap

        #Setup font
        font = QtGui.QFont()
        font.setBold(True)
        font.setCapitalization(QtGui.QFont.AllUppercase)
        font_size = self.height() ** 0.6 - 2
        font.setPixelSize(font_size)

        #Setup painter
        painter = QtGui.QPainter(self)
        painter.setFont(font)

        #Draw text
        shadow_offset = max(1, round(font_size / 10))
        padding = round(font_size / 10)
        width = self.width() - padding * 2 - shadow_offset
        height = self.height() - padding * 2 - shadow_offset
        painter.setPen(QtGui.QColor(0, 0, 0))
        painter.drawText(QtCore.QRect(padding+shadow_offset, padding+shadow_offset, width, height), text_flags, text)
        painter.setPen(QtGui.QColor(255, 255, 255))
        painter.drawText(QtCore.QRect(padding, padding, width, height), text_flags, text)

        painter.setBackground(QtGui.QColor(0, 0, 0))
def _paintEventOverride ( self , text , event ) : self . _autoGridOriginalPaintEvent ( event ) text_flags = QtCore . Qt . AlignHCenter | QtCore . Qt . AlignBottom | QtCore . Qt . TextWordWrap #Setup font font = QtGui . QFont ( ) font . setBold ( True ) font . setCapitalization ( QtGui . QFont . AllUppercase ) font_size = self . height ( ) ** 0.6 - 2 font . setPixelSize ( font_size ) #Setup painter painter = QtGui . QPainter ( self ) painter . setFont ( font ) #Draw text shadow_offset = max ( 1 , round ( font_size / 10 ) ) padding = round ( font_size / 10 ) width = self . width ( ) - padding * 2 - shadow_offset height = self . height ( ) - padding * 2 - shadow_offset painter . setPen ( QtGui . QColor ( 0 , 0 , 0 ) ) painter . drawText ( QtCore . QRect ( padding + shadow_offset , padding + shadow_offset , width , height ) , text_flags , text ) painter . setPen ( QtGui . QColor ( 255 , 255 , 255 ) ) painter . drawText ( QtCore . QRect ( padding , padding , width , height ) , text_flags , text ) painter . setBackground ( QtGui . QColor ( 0 , 0 , 0 ) )