PDA

View Full Version : QTextEdit: Problem rendering with <font> following whitespace



fifth
11th January 2015, 12:41
Hi, I'm having a problem getting QTextEdit to render a colored font which is preceded by whitespace. It renders with the appearance of each whitespace character overwriting other characters in the string. An example of the problem is ...



import sys
from PyQt5.QtWidgets import QApplication, QTextEdit

app = QApplication(sys.argv)
editor = QTextEdit()

editor.insertHtml('&nbsp;<font color="Red">HELP</font>&nbsp;<br>')
editor.insertHtml('&nbsp;&nbsp;<font color="Red">HELP</font>&nbsp;<br>')
editor.insertHtml('&nbsp;&nbsp;&nbsp;<font color="Red">HELP</font>&nbsp;<br>')
editor.insertHtml('&nbsp;&nbsp;&nbsp;&nbsp;<font color="Red">HELP</font>&nbsp;<br>')

editor.show()
app.exec_()


I would expect to get output of ...



HELP
HELP
HELP
HELP


But the actual visible output is ...



HELP
HEL
HE
H


Removing the trailing &nbsp; does render the output as expected but is required in the real code for formatting.

Any advice to get this working would be much appreciated.