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. QFontMetrics::tightBoundingRect acting strange
QtWS25 Last Chance

QFontMetrics::tightBoundingRect acting strange

Scheduled Pinned Locked Moved Solved General and Desktop
text renderingfontengine
7 Posts 2 Posters 1.4k 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.
  • S Offline
    S Offline
    SafaAlfulaij
    wrote on last edited by
    #1

    Hello all.
    I was trying hard to know why I’m getting larger rects for the text I’m using (mostly Arabic). Issue is that QFontMetrics::tightBoundingRect returns strange width sometimes.

    Check the width of these functions and you’ll see that they it is different, even though there is no change in the layout at all. I am using Noto Sans font.

    QFontMetrics::tightBoundingRect("ab")
    QFontMetrics::tightBoundingRect("a\u200Cb") // \u200C is ZWNJ character
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What version of Qt are you using ?
      On what OS ?
      What results are you getting ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S Offline
        S Offline
        SafaAlfulaij
        wrote on last edited by SafaAlfulaij
        #3

        Hi!
        I’m using Qt 5.11.1 on ArchLinux and getting these results:

        PyQt5.QtCore.QRectF(3.0, -64.0, 91.0, 65.0) \\ "ab"
        PyQt5.QtCore.QRectF(3.0, -64.0, 113.0, 65.0) \\ "a\u200Cb"
        

        Yes I’m using PyQt, but I believe it has nothing to do with the binding.

        Edit: I'm using Noto Sans, point size 62.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you show the complete code with font setup ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SafaAlfulaij
            wrote on last edited by
            #5

            Sure thing.

            # minimal code
            from PyQt5.QtGui import QGuiApplication, QFont, QFontMetricsF
            
            app = QGuiApplication(["myApp"])
            
            notoFont = QFont("Noto Sans", 62)
            notoMetrics = QFontMetricsF(notoFont)
            
            print(notoMetrics.tightBoundingRect("ab"))
            print(notoMetrics.tightBoundingRect("a\u200Cb"))
            

            Output:

            PyQt5.QtCore.QRectF(3.0, -64.0, 91.0, 65.0)
            PyQt5.QtCore.QRectF(3.0, -64.0, 113.0, 65.0)

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Which variation of the Note Sans font ? There's a lot of possibilities.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • S Offline
                S Offline
                SafaAlfulaij
                wrote on last edited by
                #7

                Well, I think that the font doesn’t really matter here. Whatever font I use I get the same problem.
                Reported bug: https://bugreports.qt.io/browse/QTBUG-70184

                1 Reply Last reply
                1

                • Login

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