Unsolved Same font, different heights
-
I develop an application that runs both under windows and (embedded) linux. In most things, Qt makes this really easy.
However, I noticed one difference: Font heights. The very same font with the very same settings may be 20 pixels high in Windows, but 22 pixels in Linux. This can change the line break behavior, so I get different results on the different systems.
Any idea what I could do about this? (we're talking 4.8.7, BTW)
-
Hi
Are you specifying the size as Points or Pixels? -
As pixel size.
Edit: Maybe I should elaborate: The differences on the OSes are the output of QFontMetrics::height() with the same font.
-
@Asperamanca
Can you test with Points size ? in theory that should be the same across
platforms.
Pixels size will vary. -
In general, the "point size" of a font is the size of the x-height + ascender area's size + descender area's size, and the point size says nothing and gives no restrictions about the width of each character. So, the only reason Arial is bigger than Times is because of its width. Any other size difference depends only on the visual style of the font design (in this case, the fact Arial has a bigger x-height).
-
With point size, it is guaranteed to vary, because I have different display DPIs. Mind that I set a certain pixel size to a font, then test the very height of the font using QFontMetrics which gives it's output in - pixels.
However, one thing occurred to me: Rounding might differ, because on Windows, qreal is defined as double, whereas on an embedded hardware without FPU, qreal is float.
-
@Tusovshik said in Same font, different heights:
In general, the "point size" of a font is the size of the x-height + ascender area's size + descender area's size, and the point size says nothing and gives no restrictions about the width of each character. So, the only reason Arial is bigger than Times is because of its width. Any other size difference depends only on the visual style of the font design (in this case, the fact Arial has a bigger x-height).
I don't quite get the point you are trying to make. I have the same font on both systems, and I am only concerned with it's height. Plus, as said, I use pixelSize, not pointSize.
-
Well
I am talking about
http://doc.qt.io/qt-5/qfont.html#setPointSize
That i used to set my font size and its looks the same on windows / linux.
If I use
http://doc.qt.io/qt-5/qfont.html#setPixelSize
It changed.
Docs
Says
"Using this function makes the font device dependent. Use setPointSize() or setPointSizeF() to set the size of the font in a device independent manner."So using setPixel is font device dependent and will change.
Update: I used Qt5.5
Maybe it was different with 4.8.7.
Also I did not check the values as it looked as expected.
It sounds like your case is more "tight" and hence its noticeable.Its not an option to check heights with QFontMetrics and simply lower the size until it's within
acceptable Heights? -
I have extensively*) studied the behaviors I get on different devices when using setPointSize and setPixelSize. If you mix graphics and text in the same display (e.g. the user draws a rectangle, an ellipse and a text), then the user expects the relations between the graphical objects and the text to stay the same, regardless of device. For example, the user places a text, and frames it nicely with a rectangle.
If the user sets the size of the rectangle in pixels, then the font must be set in pixels, too. Otherwise you will have a "nicely framed text" on one display, and a "design disaster" on another system - based on exactly the same parameters.
The alternative would be to design both objects and font in "points". An approach I experienced with a different GUI framework - and troublesome to work with.
If you get right down to it, font is always device dependent. The question is: Which parameters are you observing?
In one case (pointSize), the physical size (millimeters) of the font is supposed to be the same across multiple devices. Meddle with the DPI (e.g. I use large fonts in Windows), and the deal is off. However, even when use use the system-suggested DPI, you will have different results on different systems when you measure the size in pixels.
In the other case (pixelSize), the size in pixels is guaranteed to be the same, but the physical size might vary.There is no "perfect" solution. However, I hoped that at least, when I say 20 pixels, I get 20 pixels, no matter how big it actually looks to the user. Seems I was wrong...
As for your suggestions: Of course, I can find a workaround for this specific situation. I am rather trying to understand whether there is an underlying concept or issue I do not properly understand, or a known bug in that direction (not that I could find one).
*) When I write "extensively", I mean "over the course of several days.
-
Hi
Well you sound very informed so I doubt something you missed.
In later Qt version this issue also seen with retina class screens where all is just too small.
They added new stuff in Qt5.6 to try to help that.
https://blog.qt.io/blog/2016/01/26/high-dpi-support-in-qt-5-6/I once made a drawing program for windows and also had this issue. There i used mm internally to make sure gfx remained same pixel size using GetDeviceCaps() with HORZSIZE and VERTSIZE, HORZRES and VERTRES. Im not sure how one would do the same in Qt / portable way.
Also as you mention. Even when working fairly ok, then the Use Large font in win7 + will often not be as expected. So maybe any workaround will come in handy on different systems.