Results 1 to 11 of 11

Thread: Recompiling from Mac to Win changes apparent font size

  1. #1
    Join Date
    May 2012
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Recompiling from Mac to Win changes apparent font size

    I've created a program with QT creator 2.4.1 based on Qt 4.7.4 in a Mac.
    I used Lucida Grande Font that is the pre-defined one in Mac.
    When I recompile the program Win7, however, its appearance is much worse a lot since all text is much larger. I see that fonts are indeed converted into MS Shell; even though they maintain the same numerical value of point size, the final result is quite different.

    Does anyone know why, for instance, a 11 pts Lucida Grande txt in Mac, once in Windows is converted into a 11 pts MS Shell Dlg 2 text appears to be so larger?
    Does anyone know a systematic way to force the appearance of widget text under Mac and Win to be as near as possible to each other?

    Thanks a lot.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Recompiling from Mac to Win changes apparent font size

    It could be a number of different factors:
    • Mismatches between the assumed pixel density and actual pixel density of the display that different from OS to OS, and even between Windows versions.
    • The Windows Display Scaling "feature" which is on by default on smaller displays.
    • Perceived, but not necessarily real, differences brought about by different font shapes.


    You can set the font size in pixels rather than points (but that has its own problems).
    You can ensure Display Scaling is off when doing the comparison.
    You can use a common font rather than relying on the OS default.
    You can ensure you are using the Qt UI layout facilities so that font size changes do not automatically break your UI.

  3. #3
    Join Date
    Aug 2011
    Location
    California, USA
    Posts
    24
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Recompiling from Mac to Win changes apparent font size

    I have the same problem when using the default fonts. To fix it, I just use the layouts that Qt offers so that the UI doesn't break (just as ChrisW67 suggests). It works great!

    Chris

  4. #4
    Join Date
    May 2012
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Recompiling from Mac to Win changes apparent font size

    There is more than just font conversion in this issue.
    I enclose two pictures. Both are created using the same C++ code.
    Widgets' text is Arial (e.g. "Plot" botton text is Arial 13)

    The text label on the axes in the plot area are Times 10 and written by painter commands:
    painter->setFont(QFont("Times",10));
    and then
    painter->drawText(x,y,text);

    mac.jpgwin.jpg

    the user areas of the two windows is the same. Moreover the pixel size of the area devoted to the sinusoidal plots is the same. But the size of the number on the axes are not the same!

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Recompiling from Mac to Win changes apparent font size

    Have you ensured that Windows 7 Display Scaling is turned off?

  6. #6
    Join Date
    May 2012
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Recompiling from Mac to Win changes apparent font size

    If by display scaling you mean text scaling, it is off (i.e. 100%-96dpi).
    If you mean some different setting, please, tell me more on how to verify.

    However, any proportional display scaling cannot be active, since the whole window (excluding the border, larger for win7) has the same size in the two OS's.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Recompiling from Mac to Win changes apparent font size

    Based on the images attached it seems to me you are not using widget layouts. If you do that, you won't have to worry about the font size changes. Otherwise you'll application will fall apart on a first system installation that has a different default font size than you do.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    May 2012
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Recompiling from Mac to Win changes apparent font size

    Indeed I didn't use layouts since this is a program I use to test a plotting program core that I will later insert in an application with a much lower number of widgets, that I will create using layouts.
    This discussion has made even cleaner that layouts are pretty mandatory for widgets in Qt.

    However layouts do not manage text written directly using painters. And I found differences in the displayed size of the text on the axes, that was written using a painter. This is rather strange indeed.

    As for my application, the conclusion is:
    1) in the final program widgets will have to be put on the window by means of layouts
    2) the following code enhances text on the axes:
    fontsize= [...];
    #if defined(Q_OS_MAC)
    fontSize+=1;
    #endif
    painter->setFont(QFont("Times",fontSize));
    painter->drawText(x,y,text);

    However it is unclear why this OS-specific font enlargement is needed.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Recompiling from Mac to Win changes apparent font size

    Quote Originally Posted by mchome View Post
    Indeed I didn't use layouts since this is a program I use to test a plotting program core that I will later insert in an application with a much lower number of widgets, that I will create using layouts.
    This discussion has made even cleaner that layouts are pretty mandatory for widgets in Qt.
    Indeed they are.

    However layouts do not manage text written directly using painters.
    That's a responsibility of your widget. sizeHint() has to be implemented accordingly.

    However it is unclear why this OS-specific font enlargement is needed.
    I really wouldn't do that if I were you. Enlarge your system font and see if a static +1 in font size still looks good. Then reduce the font significantly and check if +1 is ok again. I doubt they will be. +1 looks good on your system.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    May 2012
    Posts
    28
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Recompiling from Mac to Win changes apparent font size

    Making a +1 is very rough, and is a consequence of the fact that I was not able to understand the rationale behind the smaller appearance of characters (having the same name and the same point size) in Mac systems.
    Another option could be to multiply by 1.1 the size.

    The idea behind +1 is that I want the correction to be very small, and to influence by a significant amount only the smaller fonts.
    Indeed the text fontSize on my axes is chosen as a function of the plot size (that's why I wrote [...] when I earlier discussed the fontSize definition)
    For larger plot sizes I could have up to 16 points fonts, for which +1 impacts nearly negligibly.

    I would have been much happier if no correction were needed. Once I understand why in Mac the same fonts (same name, same points) imply smaller actual characters, maybe I will not need any correction anymore.

  11. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Recompiling from Mac to Win changes apparent font size

    A 12 point font is supposed to be 12/72 inches "tall" but in digital typography that is a somewhat vague concept: the height of the virtual grid onto which the character is drawn. The characters of different fonts might occupy different amounts of that grid so a 12pt Courier and 12 pt Times may appear to be different sizes on the same system despite the virtual grid having the same height.

    To arrive at a 12/72" high virtual grid on screen or paper the rendering software needs to know the actual pixel density of the device (dots per inch, DPI). Once that is known the number of device pixels needed to obtain the desired height is calculable. If the device reports accurate DPI figures, and the renderer takes heed, then the result should be close to an accurate physical height for the virtual grid (Some variation comes from rounding to whole pixels).

    Windows, until recently, assumed all screens were 96 dots-per-inch regardless of whether the device reported its actual dimensions. Consequently a 12pt font is drawn on a virtual grid 16 pixels high regardless of how high that appears on screen. With the display scaling "feature" in play that assumption can be changed (120 or 144 DPI are the other fixed options) resulting in larger physical display of fonts of the same point size.

    As I understand it, X11 has always taken actual display DPI into consideration but until recent years has not had a very reliable report on the actual device DPI and would often be configured with bitmap fonts for 75 or 100 DPI before scalable fonts were readily available. Mac, historically on very controlled hardware or only using recent devices, has always had the pleasure of an actual device DPI and produces fonts of close to the expected physical size.

    Consequently 12pt Arial on Windows, X11, and Mac displayed on the same monitor may be different physical sizes on screen.

Similar Threads

  1. Replies: 1
    Last Post: 30th March 2012, 16:46
  2. Font Height and width based on font size
    By Ghufran in forum Qt Programming
    Replies: 1
    Last Post: 31st July 2010, 08:02
  3. Replies: 6
    Last Post: 27th July 2010, 21:07
  4. adjust font size to QLabel-size
    By hunsrus in forum Qt Programming
    Replies: 0
    Last Post: 9th July 2008, 14:33
  5. change font size and button size of QMessageBox
    By nass in forum Qt Programming
    Replies: 6
    Last Post: 13th September 2006, 19:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.