Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt fonts have different sizes on different systems

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.

like image 847
user1765274 Avatar asked Jun 26 '13 12:06

user1765274


2 Answers

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.

like image 192
Liz Avatar answered Sep 22 '22 08:09

Liz


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.

like image 21
차전경 Avatar answered Sep 19 '22 08:09

차전경