5

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?

enter image description here

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_()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
alphanumeric
  • 17,967
  • 64
  • 244
  • 392

1 Answers1

4

You must apply the font to all the menu as shown below:

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_()

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • The only way to set the font globally for all menus that I've found is with stylesheets: `qApp->setStyleSheet("* {font-family: Verdana;}");` (or specify `QMenu` selector instead of `*` to set the font just for the menus). – Violet Giraffe Jun 23 '22 at 13:28