QPlainTextEdit change font
-
I have a problem with changing the font of a
QPlainTextEdit
: I am able to change the font if I useQWidget::setFont()
before text is actually added to the text edit. However, I am unable to change the font of the text edit if it is already displaying text.
Is it impossible to change the font of aQPlainTextEdit
that already contains text? I'd like to avoid clearing and re-reading the file that it is displaying. -
HI,
Unless I'm mistaken, you need to modify QPlainTextEdit's document and change the font for all the texts where you want that to change.
-
I could use a hand here. It seems to be a simple task but after going over the documentation thrice I still haven't found the proper way of doing this.
As far as I can tell I am supposed to iterate over all
QTextBlock
s of theQTextDocument
and useQTextCharFormat
to change the font. However, I can't figure out how to apply a newQTextFormat
to aQTextBlock
. All the text block accessor functions appear to return a copy of theQTextBlock
. I couldn't find a way of modifying it.
There also appears to be the possibility to change the font using aQTextCursor
that spans the entire content by usingQTextCursor::setBlockCharFormat()
but I am not sure whether this is the correct solution either. -
AFAIK the QTextCursor solution is the simplest.