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. Same Font family ,size. different width
Forum Updated to NodeBB v4.3 + New Features

Same Font family ,size. different width

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 4.9k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    dxwang
    wrote on last edited by
    #1

    when I use same font family ,size and weight. QFontInfo also is same. but the text width is different in different OS.(windows,ubuntu,solaris). so how to do it ? when I draw a rectangle around the text, running in different OS, because different width, text sometimes goes out. or the text is in center, but in other OS, it’s left or right, not center.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      The width of text heavily depends on the used rendering engine.
      The font rendering depends on the OS, so it might be that on windows, the system font rendering is used, on Linux freetype, which might lead to different widths.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        [quote author="dxwang" date="1303804332"]when I use same font family ,size and weight. QFontInfo also is same. but the text width is different in different OS.(windows,ubuntu,solaris). so how to do it ?[/quote]

        How to do what exactly? You can query the width using QFontMetrics. Is there anything else you need?

        1 Reply Last reply
        0
        • frankcyblogic.deF Offline
          frankcyblogic.deF Offline
          frankcyblogic.de
          wrote on last edited by
          #4

          If you disable hinting, the same TTF fonts should deliver same widths. There was an article about it recently on "labs":http://labs.qt.nokia.com/2011/03/14/hint-hint-nudge-nudge-say-no-more/ .

          There is also a way to ship your own fonts with your Qt app.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dxwang
            wrote on last edited by
            #5

            hi, Andre.
            my question is when I draw a rectangle around the text, running in different OS, because different width, text sometimes goes out. or the text is in center, but in other OS, it’s left or right, not center.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dxwang
              wrote on last edited by
              #6

              hi,unclewerner.
              if disable hinting, maybe font is not clear, has aliasing when the font size is only 7. so I use QPainter::Antialiasing、QPainter::TextAntialiasing and QFont::PreferAntialias(QFont is set to QPainter, and use QPainter to draw text).
              by the way, what’s the meaning of shiping your own fonts with your Qt app. I have tried wenquanyi 、heiti and other fonts. ony lishu(隶书) is equal width,but it’s width is double of others, and it is serif font. I want to use sansserif font to Reduce the deformation when Zooming in and out by QMatrix.
              now I have tried to modify the /etc/fonts/conf.d, delete all 10-*.conf files and add 10-unhinted.conf to this directory under ubuntu, solaris x86 and sparc. but the width is still differnt . need I to set setGraphicsSystem() to Raster ? Thanks

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                Why need the size be 100% equal on the different systems. You can query it during runtime, so you can define the rectangle size during runtime.

                Edit: and please, if you reply to two replys in the forum, you can do this in one post. Thanks

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • frankcyblogic.deF Offline
                  frankcyblogic.deF Offline
                  frankcyblogic.de
                  wrote on last edited by
                  #8

                  @dxwang: You can package the fonts you need with your application and call "QFontDatabase::addApplicationFont()":http://doc.qt.nokia.com/4.7/qfontdatabase.html#addApplicationFont.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dxwang
                    wrote on last edited by
                    #9

                    hi,unclewerner
                    In my cross-platform app. I use QFontDialog to choose fonts. indeed I need to filter the font family, for example, Arial, Courier, wenquanyi and Microsoft YaHei. I don't want to see and choose others in combo box., how I can do that? does QFontDatabase::addApplicationFont() can do it?
                    by the way, my app is cross-platform(windows xp , windows7, ubuntu, solaris x86 and sparc), but QFontDatabase::addApplicationFont() needs fontconfig to support, so it is no use for windows.

                    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