QSyntaxHighlighter text quality
John Sturtz
john at sturtz.org
Wed Nov 5 03:19:54 GMT 2025
I'm not sure whether this message originally got through. I got a
response indicating it was being held until moderator review because it
was too large (because I had attached the .ttf file I was working with,
and that was > 512 Kb). The message suggested that if I didn't receive
notification of the moderator's decision, that it would get posted. And
I didn't. At least not so far.
Anyway, I found a solution/work-around for the problem.
In the Highlighter class (that's derived from QSyntaxHighlighter), I
create a QTextCharFormat object. If I call
.setFontHintingPreference(PreferNoHinting) again on that object, then
the text displayed by the syntax highlighter looks better -- like the
other text. (Line #152 in the attached file)
/John
------ Original Message ------
>From "John Sturtz" <john at sturtz.org>
To pyqt at riverbankcomputing.com
Date 11/2/2025 9:21:50 PM
Subject QSyntaxHighlighter text quality
>Hi again.
>
>With some trepidation, I have a question about fonts again. Not so
>much about fonts in general, but about display quality of the font I am
>using.
>
>I have a QTableView with a custom delegate. The delegate editor is
>implemented as a QPlainTextEdit widget which has a QSyntaxHighlighter
>associated with it.
>
>I am loading a .ttf file at runtime and using it as the display font.
>Initially the quality is pretty poor everywhere [attached screenshot
>initial.png].
>
>I found online the suggestion to create a font object, call
>.setHintingPreference(PreferNoHinting) on it, then apply that to the
>QApplication object [lines #175-177]. That seems to improve the
>display significantly.
>
>Except for the text displayed by the syntax highlighter. That text is
>still pixelated [attached screenshot highlighter.png]. It's as though
>the .setHintingPreference() call doesn't affect the syntax highlighter.
>
>Wondering if there's any way around this?
>
>Thanks again!
>
>/John
>
>[Sample code, screenshots and font file are attached]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20251105/70634d52/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.py
Type: text/x-python
Size: 5276 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20251105/70634d52/attachment.py>
More information about the PyQt
mailing list