QMenu font size for different DPI for windows

742 Views Asked by At

I tried to make a custom QWidgetAction. That works fine. However... on windows with different DPI the font in the menu changes in non-obvious ways.

  • 100% -> pointSize = 8
  • 125% -> pointSize = 9
  • 150% -> pointSize = 9

(so I was not able to fit some linear function).

I am going through Qt sources to find where the font size is set, but no luck (so far).

Maybe someone can point me to the place where the font size is set depending on DPI? (So that I can use the same calculation for my custom widget.

Thanks, guys.

1

There are 1 best solutions below

11
Parisa.H.R On

Add QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); in main.cpp and check again I think this will fix your problem.

also, this doc explains it more.

Edited:

For a setting font to QLabel you can do this in two ways :

  1. From GUI, can change the font of all widgets in GUI from here :

enter image description here

  1. create QFont object and add the same menu font to it then with the setFont function of QLabel add it.
    QFont font;
    font.setPointSize(9);
    label->setFont(font);

Default font size for all widgets and QMenu in Qt is 11.