Bold font in Label with setBold method

setBold is a method of QFont: it needs an instance of QFont. You can't call directly QtGui.QFont.setBold(), because there is nothing to be set to bold.

You have to first create the QFont object, then set it to bold, then set it as the label's font.

myFont=QtGui.QFont()
myFont.setBold(True)
self.label.setFont(myFont)

Note that self.label.setFont(QtGui.QFont().setBold(True)) wouldn't work either, because setBold returns None.

If you'd like a one-liner, QFont can be created with arguments, and one of them is the weight. For a bold Times font:

self.label.setFont(QtGui.QFont("Times",weight=QtGui.QFont.Bold))

self.label.setStyleSheet("font-weight: bold")

easier I believe

Tags:

Python

Pyqt4