Search code examples
pythonpyqtprettytable

How to make QPlainTextEdit look like a .txt file?


I have a QPlainTextEdit which shows some information in tabular form, and I added the option to save it as a .txt file. I built the table with prettytable. When I open the .txt file, it looks nice, just how I want it to look like. However, in my GUI, QPlainTextEdit shows it all unaligned. How can I make it look like in the .txt?

How I want it to look

How QPlainTextEdit shows it


Solution

  • First of all, there's no such a thing as "showing as a txt file", as txt files don't contain formatting information.

    Anyway, what you actually want is to set the font of your QPlainTextEdit to some fixed-width (or monospace) font; see this question to see how to obtain one portably.