QFontMetrics::tightBoundingRect acting strange
-
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
-
Hi,
What version of Qt are you using ?
On what OS ?
What results are you getting ? -
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.
-
Can you show the complete code with font setup ?
-
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) -
Which variation of the Note Sans font ? There's a lot of possibilities.
-
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