Problem: I want to implement a text editing widget for text with additional tags. I'd like some tags to be invisible in some cases so that they do not distract the user.
Environment: I'm using PyQt
and prefer to use QPlainTextWidget
and QSyntaxHighlighter
.
Approach: With QSyntaxHighlighter
I can set QTextCharFormat
for the strings which match my requirement. QTextCharFormat
has gives me all font properties like size, colors, etc. but: I haven't found a option to hide the text or reduce its size to zero.
I don't want to remove or replace the tags, as this will introduce a lot more code (copying should contain tags and without I can't use QSyntaxHighlighter
for formating the remaining text according to the tags).
Update: So far I found a ugly hack. By setting the QTextFormat::FontLetterSpacing to a small value, the text will consume less and less space. In combination with a transparent color the text is something like invisible.
Problem: In my test this worked only for letter spacings down to 0.016 %. Below the spacing is reseted to 100 %.
QTextEdit
. AFAIK the difference is limited to the scrolling behavior, tables, frames and things like images. The functions which might enable to hide text are the same as for theQPlainTextEdit
. Other then that there are mo more advanced classes inside Qt. QScintilla would mean using something completely different. – Jerlenejermain