Dynamic change of font color in QTextEdit
Unsolved
Qt for Python
-
I want to change the color of font basing on the user input.
More precisely, if a user gives a certain word, I want only this word to be red and leave the rest of text with the same color.I was thinking to interpret every given character and if the pattern matches, do the following:
# to move the cursor to the beginning of given input pattern self.textEdit.moveCursor(QTextCursor.End - 3) responseStyle = "<span style=\" color:" + RESPONSE_COLOR + ";\" >" # change the style self.textEdit.insertHtml(responseStyle) self.textEdit.moveCursor(QTextCursor.End) # end the changed style section self.textEdit.insertHtml("</span>")
However, the color doesn't change.
Does anyone have an idea how to solve it? -
Hi,
Sounds a bit like you need QSyntaxHighlighter.