'PySide2 - QStyledItemDelegate: Get back default text interaction
I wanted to know if it is possible to recover the default interaction with the text after painting it in a delegate. For example, I paint a delegate that renders markdown, but I can't select it anymore, or click on the links etc. I haven't really found (or searched for) any information about this. I use PySide2.
example on how I paint the text in the QStyledItemDelegate paint method:
width = option.rect.right() - left - DELEGATE.BORDER_H_SPACE
doc = QTextDocument()
doc.setMarkdown(msg)
doc.setDefaultFont(option.font) # fonts will be correct when you change them via stylesheet
doc.setDocumentMargin(0) # left space
doc.setTextWidth(width)
painter.save()
painter.translate(left, top)
clip = QRectF(0, 0, width, option.rect.height())
painter.setClipRect(clip)
ctx = QAbstractTextDocumentLayout.PaintContext()
ctx.palette.setColor(QPalette.Text, painter.pen().color()) # set text color
ctx.clip = clip
doc.documentLayout().draw(painter, ctx)
painter.restore()
Thank you in advance for your answers!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
