I have a QTextEdit
in which I want to set some text (unicode) that has been generated by an ASCII Art text renderer. Everything works fine, except that the QTextEdit
is distorting the text. The screenshot shows the same unicode text variable set in the QTextEdit
via setText()
and logged to the console, where it is displayed correctly.
It doesn't seem to matter if I use QTextEdit
or QPlainTextEdit
, or if I am setting the text via setText(ascii_art_text)
or setPlainText(ascii_art_text)
. I'm using PySide here, however I suspect that isn't of too much interest in this case.
Any ideas how to fix that distortion?
From the looks of your example, it appears that your
QTextEdit
is not using a monospaced font which is what terminals and text editors typically use. Create a QFont using a monospaced font. E.g.,According to Torsten Marek's answer in How to specify monospace fonts for cross platform Qt applications?, you can get a cross platform monospaced font with:
Once you've determined your font, assign it to your
QTextEdit
: