The about
function is a static method: it is a "helper", which automatically constructs a message box, runs its exec()
and returns its result. This means that there's no way to access the message box instance and, therefore, its font.
Note that, since it's a static method, there's no use in creating a new instance of QMessageBox, as you could call about
on the class alone:
QMessageBox.about(self.parent(), "About", "Appli\nVersion 0.0")
According to the sources, on MacOS Qt automatically uses a bold font for the label of all message boxes.
The solution is to avoid the static method, and create a new instance of QMessageBox. Since the label widget is private, the only way to access it is through findChild()
, which on PyQt allows us to use both a class and an object name; luckily, Qt sets an object name for the label (qt_msgbox_label
), so we can access it and set the font accordingly:
def showAbout(self):
msgBox = QMessageBox(QMessageBox.NoIcon, 'About', 'Appli\nVersion 0.0',
buttons=QMessageBox.Ok, parent=self.parent())
# find the QLabel
label = msgBox.findChild(QLabel, 'qt_msgbox_label')
# get its font and "unbold" it
font = label.font()
font.setBold(False)
# set the font back to the label
label.setFont(font)
msgBox.exec_()