-def paint(self, painter, option, index):
- text = index.model().data(index).property('content').toString()
- palette = QApplication.palette()
- document = QTextDocument()
- document.setDefaultFont(option.font)
- if option.state & QStyle.State_Selected:
- rx = QRegExp(QString('<font .*>'))
- rx.setMinimal(True)
- # If selected, I remove the <font color="..."> by hand,
- # and give the highlight color
- document.setHtml(QString("<font color=%1>%2</font>") \
- .arg(palette.highlightedText().color().name())\
- .arg(text.replace(rx, QString('')).
- replace(QString('</font>'),QString(''))))
- else:
- document.setHtml(text)
- color = palette.highlight().color() \
- if option.state & QStyle.State_Selected \
- else palette.base().color()
- painter.save()
- # voodoo: if not highlighted, filling the rect
- # with the base color makes no difference
- painter.fillRect(option.rect, color)
- painter.translate(option.rect.x(), option.rect.y())
- document.drawContents(painter)
- painter.restore()
-
+ def paint(self, painter, option, index):
+ text = index.model().data(index).property('content').toString()
+ palette = QApplication.palette()
+ document = QTextDocument()
+ document.setDefaultFont(option.font)
+ if option.state & QStyle.State_Selected:
+ rx = QRegExp(QString('<font .*>'))
+ rx.setMinimal(True)
+ # If selected, I remove the <font color="..."> by hand,
+ # and give the highlight color
+ document.setHtml(QString("<font color=%1>%2</font>") \
+ .arg(palette.highlightedText().color().name())\
+ .arg(text.replace(rx, QString('')).
+ replace(QString('</font>'),QString(''))))
+ else:
+ document.setHtml(text)
+ color = palette.highlight().color() \
+ if option.state & QStyle.State_Selected \
+ else palette.base().color()
+ painter.save()
+ # voodoo: if not highlighted, filling the rect
+ # with the base color makes no difference
+ painter.fillRect(option.rect, color)
+ painter.translate(option.rect.x(), option.rect.y())
+ document.drawContents(painter)
+ painter.restore()