Ejemplo n.º 1
0
    def drawDisplay(self, painter, option, rect, text):
        """
        Overloads the drawDisplay method to render HTML if the rich text \
        information is set to true.
        
        :param      painter | <QtGui.QPainter>
                    option  | <QtGui.QStyleOptionItem>
                    rect    | <QtCore.QRect>
                    text    | <str>
        """
        if self.showRichText():
            # create the document
            doc = QtGui.QTextDocument()
            doc.setTextWidth(float(rect.width()))
            doc.setHtml(text)

            # draw the contents
            painter.translate(rect.x(), rect.y())
            doc.drawContents(
                painter,
                QtCore.QRectF(0, 0, float(rect.width()), float(rect.height())))

            painter.translate(-rect.x(), -rect.y())
        else:
            if type(text).__name__ not in ('str', 'unicode', 'QString'):
                text = nativestring(text)

            metrics = QtGui.QFontMetrics(option.font)
            text = metrics.elidedText(
                text, QtCore.Qt.TextElideMode(option.textElideMode),
                rect.width())

            painter.setFont(option.font)
            painter.drawText(rect, int(option.displayAlignment), text)
Ejemplo n.º 2
0
 def adjustHeight(self, column):
     """
     Adjusts the height for this item based on the columna and its text.
     
     :param      column | <int>
     """
     tree = self.treeWidget()
     if not tree:
         return
     
     w = tree.width()
     if tree.verticalScrollBar().isVisible():
         w -= tree.verticalScrollBar().width()
     
     doc = QtGui.QTextDocument()
     doc.setTextWidth(w)
     doc.setHtml(self.text(0))
     height = doc.documentLayout().documentSize().height()
     self.setFixedHeight(height+2)