Qt跨平台的Windows& Mac:字体大小 [英] Qt Cross-platform Windows & Mac: Font size
问题描述
我正在使用Qt框架在Windows和OS X上开发应用程序。
问题是我已经手动设置了一些小部件的字体大小(在UI设计器中)。 >
在windows下,字体是完美的,但在osx上,它们太大了。
实际上,字体系列被转换(MS Shell Dlg 2到Lucida Grande),而不是字体大小,如果他们已经手动设置。所以我决定减少代码中的字体大小,使用一些#ifdef,例如:
#ifdef Q_OS_MAC
QFont font = ui-> button-> font();
font.setPixelSize(12);
ui-> button-> setFont(font);
#endif
这是有效的,但是当你有很多小部件的时候,所以我打开任何其他的想法。
我也有一个qtextedit有这个问题,这个解决方案不起作用,因为它是需要的HTML代码要求调整。
谢谢
href =http://qt-project.org/doc/qt-4.8/stylesheet.html =nofollow>样式表在 application ,或者一个小部件(及其子)。例如:
#ifdef Q_OS_MAC
window-> setStyleSheet(QWidget {font-size:12px} );
#endif
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
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
这篇关于Qt跨平台的Windows& Mac:字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!