我用如下代码高亮了textedit中选中的文字
text = self.textEdit
#text.setPlainText(text.toPlainText())
textColorFormat = QTextCharFormat()
textColorFormat.setBackground(QColor("red"))
text.textCursor().setCharFormat(textColorFormat);
text.textCursor().clearSelection()
但每次触发高亮动作时我都想先去除先前所有的格式后再进行。
本来我想用#注释掉的语句复原原先的plaintext,但这样连高亮都无法实现了(没报错)。
请问一下如何实现这个功能