Qt fonts have different sizes on different systems

北战南征 提交于 2020-06-25 21:13:15

问题


Using Qt Designer for the creation of ui-files, the following problem occurred:

Opening the same ui-file on a different Linux system results in different displaying of the font sizes. So, the ui-files created on one system may have too large fonts, when opening them with Qt Designer on another system. This makes text unreadable in many cases. The "point size" of the widgets is the same on both systems, but in order to make it readable on both, I have to manually decrease the point size in Qt Designer on one system currently. What can I do to assure the readablility of fonts on all systems?

Used systems are SLES 10, SLES11, Debian.


回答1:


I have encountered a similar problem. In our case it had to do with the local Linux font settings. And since we couldn't force all computers in the world to use the same font we override the font in our application.

QFont _Font("Tahoma", 8);
QApplication::setFont(_Font);

You should do this before your main window is created.

The only risk I know of is, if by some chance the font you select is not installed on the computer, I believe it will go back to the default.

I hope that helps.




回答2:


Use void QFont::setPixelSize(int pixelSize) instead of ::setPointSize.

Using this function makes the font device dependent. Use setPointSize() or setPointSizeF() to set the size of the font in a device independent manner.




回答3:


I migrated from Windows8 to Windows8, and the font size dont match. I tried to force it via the main.cpp using

QFont _Font("Tahoma", 8);
_Font.setPixelSize(8);
QApplication::setFont(_Font);

It did change some items, but some didnt. I tried to check the Class configuration but didnt find any think that will help.



来源:https://stackoverflow.com/questions/17320263/qt-fonts-have-different-sizes-on-different-systems

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