Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class HTMLDelegate(Qw.QStyledItemDelegate):
- def __init__(self, parent=None):
- super().__init__()
- self.doc = Qg.QTextDocument(self)
- def paint(self, painter, option, index):
- painter.save()
- options = Qw.QStyleOptionViewItem(option)
- self.initStyleOption(options, index)
- self.doc.setHtml(options.text)
- options.text = ""
- style = Qg.QApplication.style() if options.widget is None \
- else options.widget.style()
- style.drawControl(Qw.QStyle.CE_ItemViewItem, options, painter)
- ctx = Qg.QAbstractTextDocumentLayout.PaintContext()
- if option.state & Qw.QStyle.State_Selected:
- ctx.palette.setColor(Qg.QPalette.Text, option.palette.color(
- Qg.QPalette.Active, Qg.QPalette.HighlightedText))
- else:
- ctx.palette.setColor(Qg.QPalette.Text, option.palette.color(
- Qg.QPalette.Active, Qg.QPalette.Text))
- textRect = style.subElementRect(
- Qw.QStyle.SE_ItemViewItemText, options)
- if index.column() != 0:
- textRect.adjust(5, 0, 0, 0)
- thefuckyourshitup_constant = 4
- margin = (option.rect.height() - options.fontMetrics.height()) // 2
- margin = margin - thefuckyourshitup_constant
- textRect.setTop(textRect.top() + margin)
- painter.translate(textRect.topLeft())
- painter.setClipRect(textRect.translated(-textRect.topLeft()))
- self.doc.documentLayout().draw(painter, ctx)
- painter.restore()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement