[Interest] Achieving resolution independent font sizes with Qt

Andreas Pakulat apaku at gmx.de
Fri Jun 7 17:29:36 CEST 2013


Hi

On Fri, Jun 7, 2013 at 3:57 PM, Nikos Chantziaras <realnc at gmail.com> wrote:

> Is there an approach I can take to make the font sizes in applications
> independent of the current resolution?  For example, let's say I choose
> a font with a 12pt size, meaning setting it with
> QFont::setPointSize(10).  If the font is displayed while the monitor's
> resolution is 1920x1080, the font is rather small.  Now if I quit the
> application, switch the monitor to 640x480 (scaling-up but preserving
> the aspect ratio), the font is quite big.  As a side effect of this,
> even if my application is going fullscreen and always using a display
> area of a 4:3 ratio, only about half the text fits when the resolution
> is 640x480.
>
> What would be a good way of making sure that a font looks the same size
> on screen regardless of resolution?  I'm on Linux, but I'm hoping
> there's a portable way to achieve that.
>

This has nothing to do with Qt itself really, your problem is that the
display server does not calculate the DPI value based on resolution and
monitor size, but rather is set to the same value no matter what resolution
is being used. You can see the current DPI of your X server using xpdyinfo
(look for resolution:). If that value does not change when you change your
resolution it explains why the fonts with the same point-size suddenly get
rendered bigger. You need to find out who sets this fixed dpi value and let
the X server figure out the right value based on your monitors size and the
wanted resolution. This will only work if your monitor advertizes its sized
via the so-called EDID information. If that fails you can still help X via
its configuration file and tell it the dimensions of your monitor.

The fontconfig library may also play a role here as it has its own setting
for DPI and fontconfig is afaik being used by Qt these days to render the
fonts.

Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130607/9a3738bb/attachment.html>


More information about the Interest mailing list