(Sep-30-2022, 02:37 AM)Larz60+ Wrote: have you seen: https://doc.qt.io/qtforpython-5/PySide2/...ghter.html
which has ample examples.
Thank you for replying; yes, I saw those examples, but all of those are based around setFormat() which applies a format. I have a document to which I have already applied formatting and saved to html, but now I want to able to reload that document, select a highlighted section and identify the format applied and then remove or change the format. The QSyntaxHighlighter Class suggests that this is possible - " in addition you can use the class to query a document's current formatting", but I see not specific examples showing how to do that:
The function : "QTextCharFormat QSyntaxHighlighter::format(int position) const - Returns the format at position inside the syntax highlighter's current text block." seems to be what one would use, but I cannot see examples of how that would be used to interrogate an existing formatted document.
At the moment I have a simple function which applies a format.
def highlightWord(self):
color = QColor(Qt.yellow).lighter()
format = QTextCharFormat()
format.setBackground(QBrush(color))
cursor = self.editor.textCursor()
if not cursor.hasSelection():
cursor.select(QTextCursor.WordUnderCursor)
cursor.mergeCharFormat(format)
I am trying to create a function that can detect a highlighted section and offer the option to remove it.