Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cross platform and font sizes
Forum Update on Monday, May 27th 2025

Cross platform and font sizes

Scheduled Pinned Locked Moved General and Desktop
13 Posts 6 Posters 8.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ronM71
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      Determine the amount of space allowed, then use QFontMetrics to calculate the appropriate font size.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • R Offline
        R Offline
        ronM71
        wrote on last edited by
        #3

        Will give it a try. thanks.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mario
          wrote on last edited by
          #4

          Franzk: Maybe I'm just lazy here but how do you use QFontMetrics to calculate the font size for a given width

          1 Reply Last reply
          0
          • R Offline
            R Offline
            ronM71
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mario
              wrote on last edited by
              #6

              Ok, just want to ensure that I don't miss out on some cool features :)

              1 Reply Last reply
              0
              • AlicemirrorA Offline
                AlicemirrorA Offline
                Alicemirror
                wrote on last edited by
                #7

                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.

                Enrico Miglino (aka Alicemirror)
                Balearic Dynamics
                Islas Baleares, Ibiza (Spain)
                www.balearicdynamics.com

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  ronM71
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • AlicemirrorA Offline
                    AlicemirrorA Offline
                    Alicemirror
                    wrote on last edited by
                    #9

                    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.

                    Enrico Miglino (aka Alicemirror)
                    Balearic Dynamics
                    Islas Baleares, Ibiza (Spain)
                    www.balearicdynamics.com

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      ronM71
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #11

                        "QFontDatabase::addApplicationFont() ":http://doc.qt.nokia.com/latest/qfontdatabase.html#addApplicationFont can be your friend.

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply
                        0
                        • AlicemirrorA Offline
                          AlicemirrorA Offline
                          Alicemirror
                          wrote on last edited by
                          #12

                          Thank you for the advise. I'm working too on these three platforms and should have the same fonts everywhere.

                          Enrico Miglino (aka Alicemirror)
                          Balearic Dynamics
                          Islas Baleares, Ibiza (Spain)
                          www.balearicdynamics.com

                          1 Reply Last reply
                          0
                          • T Offline
                            T Offline
                            trusktr
                            wrote on last edited by
                            #13

                            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.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved