Insert html in new line after pressing return/enter in QTextEdit -PySide6
Unsolved
General and Desktop
-
I'm trying to insert special characters at beginning of new lines in QTextEdit when I press enter/return, like how QTextList have decorations. But the following code inserts the html on the same line before moving to the next line.
class ed(QTextEdit): def __init__(self): super(ed, self).__init__() self.installEventFilter(self) def insertLine(self): cur = self.textCursor() cur.insertHtml("<span>✧</span><span> </span>") self.setCursor(cur) def eventFilter(self, o, e): if e.type() == QEvent.KeyPress: if e.key() == Qt.Key_Return: self.insertLine()
I tried
KeyRelease
and it kind of works. But it starts inserting typed letters if i type fast while moving to next line.
I tried to make use of QTextListFormat but it doesn't support custom decorations.
Can I make use of QTextList to achieve what I'm trying to do?
How to insert the html after the cursor moves to next line, not before?