Home > Software design >  Menu font too large in PySide6 app on Windows
Menu font too large in PySide6 app on Windows

Time:01-09

The font size of menus and menu entries in a PySide6 app on Windows is way too large when scaling is greater than 100%. I have it set to 150% (on a 4K monitor) and it looks like this:

enter image description here

Notice that text in the main window ("Test HiDPI scaling") is correctly sized.

Here is a minimal example to reproduce the issue:

import sys

from PySide6.QtCore import Qt
from PySide6.QtGui import QAction
from PySide6.QtWidgets import QApplication, QLabel, QMainWindow

app = QApplication(sys.argv)
win = QMainWindow()

menubar = win.menuBar()
file_menu = menubar.addMenu("File")
file_menu.addAction(QAction("New", win))
file_menu.addAction(QAction("Open", win))
file_menu.addAction(QAction("Quit", win))
edit_menu = menubar.addMenu("Edit")
edit_menu.addAction(QAction("Copy", win))
edit_menu.addAction(QAction("Paste", win))
edit_menu.addAction(QAction("Cut", win))
view_menu = menubar.addMenu("View")
view_menu.addAction(QAction("Zoom in", win))
view_menu.addAction(QAction("Zoom out", win))
view_menu.addAction(QAction("Reset", win))
help_menu = menubar.addMenu("Help")
help_menu.addAction(QAction("Show help", win))

label = QLabel("Test HiDPI scaling")
label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)

win.setCentralWidget(label)
win.show()

sys.exit(app.exec())

To run this example,

  • save it as e.g. main.py,
  • install dependencies with pip install PySide6,
  • and run it with python main.py.

CodePudding user response:

I had the same issue. This seems to be a regression in the latest version (PySide6 6.4.1). Downgrading to the previous version (6.4.0.1) fixes the issue.

  • Related