Cross platform and font sizes
-
wrote on 24 Feb 2011, 18:33 last edited by
I'd like to hear your take on the issue. I have a fixed size window widget. Textual labels on it.
If on Mac, the label takes 50% of the width of my available space, in Ubuntu for instance, with the same text and font size, it would take 70% and on Windows, it's 35% This makes the width required for text labels unpredictable from platform to platform.
How do you deal with something like that?
-
wrote on 24 Feb 2011, 18:39 last edited by
Determine the amount of space allowed, then use QFontMetrics to calculate the appropriate font size.
-
wrote on 24 Feb 2011, 19:31 last edited by
Will give it a try. thanks.
-
wrote on 25 Feb 2011, 11:40 last edited by
Franzk: Maybe I'm just lazy here but how do you use QFontMetrics to calculate the font size for a given width
-
wrote on 25 Feb 2011, 15:54 last edited by
mario: I guess you start by measuring the width of the current font. If it exceeds the width you allocated for it, you begin a loop of testing it with smaller sizes until it fits in your allocated boundaries.
-
wrote on 25 Feb 2011, 19:08 last edited by
Ok, just want to ensure that I don't miss out on some cool features :)
-
wrote on 25 Feb 2011, 22:06 last edited by
Hi,
I'm interested to this method. Me too experienced the same problem. I used font size in point, to be sure that the size will be proportional and the same under ubuntu and windows, but this don't happens.
But I have also seen that is not clear how does works the font family specification.
-
wrote on 25 Feb 2011, 22:11 last edited by
Someone once mentioned to me you can actually store the true type font as resource so that the font output is identical through all platforms. never tried it though
-
wrote on 25 Feb 2011, 22:27 last edited by
It's a very interesting feature!!!
This has also the advantage that the same font can be ported on different platforms (almost desktop). If you have more info about this please tell me. Thanks.
-
wrote on 25 Feb 2011, 22:58 last edited by
I am finishing some other aspects of my code, but I will get to the font question very soon. Font wise, my app has to look identical as much as possible on OSX, Windows and Ubuntu. I have no intention of starting all kind of private cases in my code to support all of them individually. Gee, I hope it won't come to that anyway.
-
wrote on 25 Feb 2011, 23:03 last edited by
"QFontDatabase::addApplicationFont() ":http://doc.qt.nokia.com/latest/qfontdatabase.html#addApplicationFont can be your friend.
-
wrote on 25 Feb 2011, 23:31 last edited by
Thank you for the advise. I'm working too on these three platforms and should have the same fonts everywhere.
-
wrote on 13 Jul 2014, 04:27 last edited by
I know the thread is old, but I'd like to recommend for anyone who stumbles on this to use physical values (i.e. pt, in, mm, pc, etc) for your measurements, not pixel values. We can assume that most displays follow the VESA EDID standard, and we can rely on a point (pt) actually being 1/72 of an inch on the screen.
In Qt C++, you can use the "QScreen":http://qt-project.org/doc/qt-5/qscreen.html class to get all sorts of info regarding the screen including the dimensions of your screen in mm. In QML, the "Screen":http://qt-project.org/doc/qt-5/qml-qtquick-window-screen.html type is available with a similar subset of info. You can use this info to determine what type of device you are on and how your UI should react.
With this info, you can infer what size the device or viewing area of your app is. With this knowledge, you can decide whether to use measurements relative to the width of the viewing area, or physical values. For example, you might decide to set the base font size of your app to 16pt, or two 10% of the app width, then you can use relative values based on the base font size to render bigger or smaller fonts.