How to change QMenu font size

alp*_*ric 5 python pyqt pyqt4 qmenu qfont

The code below creates a Menu with 5 Submenus and 10 Actions per each Submenu. Even while the setPointSize command is applied to the Submenus their font seem to be unaffected and it remains to be large. But the Actions font is set to a smaller size even while the command is performed on Submenus and not the Actions. How to change the font size for both the Submenus and Actions?

在此输入图像描述

from PyQt5.QtWidgets import QMenu, QApplication
app = QApplication([])

menu = QMenu()
for i in range(5):
    submenu = menu.addMenu('Submenu %04d' % i)
    font = submenu.font()
    font.setPointSize(10)
    submenu.setFont(font)
    for n in range(10):
        action = submenu.addAction('Action %04d' % n)

menu.show()
app.exec_()
Run Code Online (Sandbox Code Playgroud)

eyl*_*esc 4

您必须将字体应用于所有菜单,如下所示:

from PyQt5.QtWidgets import QMenu, QApplication
app = QApplication([])

menu = QMenu()
font = menu.font()
font.setPointSize(18)
menu.setFont(font)
for i in range(5):
    submenu = menu.addMenu('Submenu %04d' % i)
    submenu.setFont(font)
    for n in range(10):
        action = submenu.addAction('Action %04d' % n)

menu.show()
app.exec_()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述