How do you get System default font settings in Qt?

泄露秘密 提交于 2019-11-30 11:13:23
Balázs Édes

I can think of two possible solution:

  1. You could pack with your application a font as a resource file, this way all platforms will use that font regardless the current systems default font.

  2. The QFont class has a method called defaultFamily(). Using this you could manually set the default font for your whole QApplication.

An example (main method):

QApplication application(argc, argv);
QFont font;
font.setFamily(font.defaultFamily());
application.setFont(font);
...rest of your code...

Qt will call Windows API SystemParametersInfo to get fonts for QMenu, QMessageBox etc. , and use GetStockObject to get default system font. Some widgets have special font which is different to system default one. I think Qt is doing the right thing, but the default Japanese/Chinese serif font looks bad on HiDPI monitors.

Just use QFont QApplication::font ( const char * className ) to get the right font (Meryo in your case), such as qApp->setFont(QApplication::font("QMenu"))

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!