Solved Space disappears after using Qstylesheet in QLabel
-
I want to let label_8 show different colors text. So I used stylesheet to do this. But I found that if stylesheet is used, the space in the string becomes useless.
self.main_ui.label_8.setText(f'X: {x}, Y: {y} ' f'<font color=red> R: {r}, </font>' f'<font color=green> G: {g}, </font>' f'<font color=blue> B: {b} </font>')
As the following picture shows, the text becomes compact.
Is there a way to adjust the space among different words and at the same time, keep only one QLabel being used. -
@feiyuhuahuo
Since you have to use HTML text to put your colours in, you know that multiple spaces in HTML source only produce a single space in display output. I don't know what exactly QSS accepts, but try
for an unbreakable space for each space desired, or a<pre>
or maybe separate<span>
s, or whatever works.