class HTMLDelegate(QStyledItemDelegate):
def paint(self, painter, option, index):
self.initStyleOption(options, index)
else options.widget.style()
doc.setHtml(options.text)
options.text = ""
style.
drawControl(QStyle.
CE_ItemViewItem, options, painter
)
if option.
state & QStyle.
State_Selected: ctx.
palette.
setColor(QPalette.
Text, option.
palette.
color(
textRect
= style.
subElementRect(QStyle.
SE_ItemViewItemText, options
) painter.save()
painter.translate(textRect.topLeft())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)
painter.restore()
def sizeHint(self, option, index):
self.initStyleOption(options, index)
doc.setDocumentMargin(1)
doc.setHtml(options.text)
return QSize(doc.
idealWidth(),
23)
class HTMLDelegate(QStyledItemDelegate):
def paint(self, painter, option, index):
options = QStyleOptionViewItem(option)
self.initStyleOption(options, index)
style = QApplication.style() if options.widget is None \
else options.widget.style()
doc = QTextDocument(self)
doc.setHtml(options.text)
options.text = ""
style.drawControl(QStyle.CE_ItemViewItem, options, painter)
ctx = QAbstractTextDocumentLayout.PaintContext()
if option.state & QStyle.State_Selected:
ctx.palette.setColor(QPalette.Text, option.palette.color(
QPalette.Active, QPalette.HighlightedText))
textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
painter.save()
painter.translate(textRect.topLeft())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)
painter.restore()
def sizeHint(self, option, index):
options = QStyleOptionViewItem(option)
self.initStyleOption(options, index)
doc = QTextDocument(self)
doc.setDocumentMargin(1)
doc.setHtml(options.text)
return QSize(doc.idealWidth(), 23)
To copy to clipboard, switch view to plain text mode
Bookmarks