'Reimplementation of drawContents to limit the drawing
inside `textRext`.'

def drawContents(self, painter):

    painter.setPen(self.__color)
    painter.setFont(self.font())
    if self.__textRect:
        rect = self.__textRect
    else:
        rect = self.rect().adjusted(5, 5, (-5), (-5))
    tformat = self.__textFormat
    if (tformat == Qt.AutoText):
        if mightBeRichText(self.__message):
            tformat = Qt.RichText
        else:
            tformat = Qt.PlainText
    if (tformat == Qt.RichText):
        doc = QTextDocument()
        doc.setHtml(self.__message)
        doc.setTextWidth(rect.width())
        cursor = QTextCursor(doc)
        cursor.select(QTextCursor.Document)
        fmt = QTextBlockFormat()
        fmt.setAlignment(self.__alignment)
        cursor.mergeBlockFormat(fmt)
        painter.save()
        painter.translate(rect.topLeft())
        doc.drawContents(painter)
        painter.restore()
    else:
        painter.drawText(rect, self.__alignment, self.__message)
