Can't make Bold font for label. What is wrong with my code?
self.label = QtGui.QLabel('Bla', self)
self.label.setFont(QtGui.QFont.setBold(True))
self.label.setStyleSheet("font-weight: bold")
easier I believe
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With