Qt Cross-platform Windows & Mac: Font size

被刻印的时光 ゝ 提交于 2019-12-20 02:32:31

问题


I'm developing an application on Windows and OS X, with Qt framework.
The problem is that I have manually set up the font size for some widgets (in the ui designer).
Under windows, the fonts are perfect, but on osx, they are too big.
Indeed, the font families are converted (MS Shell Dlg 2 to Lucida Grande), but not the font size, if they have been manually set.

So I decided to decrease the font size in the code, with some #ifdef, like this for example:

#ifdef Q_OS_MAC
QFont font = ui->button->font();
font.setPixelSize(12);
ui->button->setFont(font);
#endif

It's working but it's a bite annoying when you have a lot of widgets, so I'm open for any other ideas.

I have also a qtextedit which has this problem, and this solution doesn't works, cause it's the html code which need to be adjusted.

Thanks


回答1:


You may try style sheet set globally in the application, or one widget (and its subs) at a time. Something like:

#ifdef Q_OS_MAC
window->setStyleSheet("QWidget{font-size:12px}");
#endif


来源:https://stackoverflow.com/questions/11640843/qt-cross-platform-windows-mac-font-size

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