In PyQt5, both QLabel and QPlainTextEdit Widgets appear to shrink multiple whitespaces in to one. Say if I set the label text to: "abc abc abc"
, text shown is "abc abc abc"
.
Apparently, this is happening because of the default html formatting these widgets are using.
Is there a way to set these widgets to show the original text with multiple spaces keeping the original formatting ?
Edit:
QLabel- I was able to get this sorted by introducing <pre>
tags. Can anyone help with the QPlainTextEdit ?
The QPlainTextEdit
class does not reduce multiple whitespace, and it does not support html at all (as is suggested by the name). The QLabel
class also does not reduce multiple whitespace unless you explicitly include html tags (and if you can't avoid that, you can simply use <pre>
tags where necessary).
However, I suspect you may be using a variable-width font that has relatively narrow space characters, so the apparent whitespace reduction is actually illusory. If you use a fixed-width font instead, the illusion should disappear.