Start New Discussion within our Software Development Community

A small test program exploring the PySide/PyQT Label widget. With HTML code you can do some nice formatting of the label's text.

very simple template to test PySide widgets like
QLabel, QVBoxLayout, QGroupBox

QLabel accepts a HTML formatted string
for result see:

PySide is the official LGPL-licensed version of PyQT
download from:

for more info see:

tested with Python27/33 and PySide112  by  vegaseat  08feb2013

from PySide.QtCore import *
from PySide.QtGui import *

# replace [] with sys.argv for commandline
app = QApplication([])

# ----- start your widget test code ----

group_box = QGroupBox("QLabel test")

s = "Hello World!"
label_1 = QLabel()
label_1.setText(s + " (normal)")
# use HTML code to show text in color and larger size
s_html = "<font color=red size=5> {} </font>".format(s)
label_2 = QLabel(s_html)
# use HTML code to bring in a font
s_html2 = '''\
<font face="Times New Roman" color=blue size=7> {} </font>
label_3 = QLabel(s_html2)
# more HTML code ...
s4 = """\
<font size=5>
<p><b>This text is bold</b></p>
<p><strong>This text is strong</strong></p>
<p><big>This text is big</big></p>
<p><em>This text is emphasized</em></p>
<p><i>This text is italic</i></p>
<p><small>This text is small</small></p>
<p>This is<sub> subscript</sub> and <sup>superscript</sup></p>
label_4 = QLabel(s4)

vbox = QVBoxLayout()

# ---- end of widget test code -----

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.