[PySide] QPlainTextEdit with QSyntaxHighlighter turn highlighting on and off
elguavas at gmail.com
Fri May 15 02:28:42 CEST 2020
i have a QPlainTextEdit that i am using a QSyntaxHighlighter with. all
is working well and syntax is correctly highlighted while editing and on
there are 2 things i would like to achieve:
1. the most important thing is, on file open/load, to have syntax
highlighting turned off for the load/open (that is, load as
unhighlighted plain text) and then have the highlighting occur after
the text is loaded. (the main reason for this is loading a large text
that needs highlighting causes the text edit to be blank until the
highlighting is finished.)
2. the second thing is to allow the user to toggle syntax highlighting
on and off, that is, when it is turned off the text is displayed
unhighlighted, and when it is turned on text is displayed highlighted.
i've tried many things from the pyside2 and qt5 documentation and from
forums and mailing lists, but i cannot get this to work.
things i've tried include:
setting the QSyntaxHighlighter document to an empty QTextDocument(), and
then back to the QPlainTextEdit.document(). this apparently should work
but it does not.
having a flag in my ui that is set to True or False when highlighting is
wanted/unwanted and using the flag in
QSyntaxHighlighter().highlightBlock().this does not highlight on text
load, and after that only within a block then being edited.
can anyone point me in the right direction to achieve this in pyside2 code?
thanks for your time for any replies.
More information about the PySide