PDA

View Full Version : How to handle cross platform font sizes



Berryblue031
27th June 2011, 14:14
After developing my app on windows I have recently started to look at it on mac and I have encountered what must be a very common problem with font sizes.

When I have used a QLabel for header text I have set the font-size on windows to be bigger, because qt doesn't support (that I know of) the concept of setting the size to "larger" I have set a pt value. But this messes up the text on mac actually making it smaller then standard text because it uses a different font all together and the sizes are very different.

So what is the best way of specifying a QLabel to be essentially a header?

SixDegrees
27th June 2011, 14:35
The size difference is more likely due to different screen resolutions. In any case, when your program starts up you can obtain the screen DPI, then iterate over a range of font sizes until you find one that renders a given string to a length of, say, one inch. The point size may differ from font to font and from platform to platform, but the rendered size will be approximately the same across all systems.

You can never do better than an approximation, though. Other factors, like the font rendering engine, particular font involved, kerning settings and more will cause even identically named and sized fonts to render differently on different platforms. You can, however, get "close enough" using an approach like that outlined above.

Berryblue031
27th June 2011, 14:55
Hmmm that may be a bit overkill I don't really care how big the text renders on the screen. I think it's safe to assume that a platform's default font is legible, all I want to do is to make "header" labels use a bigger font size ( like 125% of the size ) regardless of what font is being used I know I can do this programmatically but that's a pain and then what you see in the designer isn't what you get.

Is there a syntax via style sheets for font-size: larger or something similar to what you can do in html?