Apparent inconsistency with QFontMetrics::width()
-
When my app starts up I am creating a QFont from stored user-configured data (font family, point size and style). At this point QFontMetrics::width() returns the wrong value for the width of the string (around 75% of the correct value depending on the font). If I subsequently open a QFontDialog and select exactly the same font, the value returned is correct. The following extracts from my debug file show the problem. The test string in this example is "The quick brown fox jumps over the lazy dog".
On start-up the font info is as follows:
Font family Comic Sans MS, point size 10, word spacing 0.000000, letter spacing 0.000000, kerning 1, pixel size -1, fixed pitch 0, params 0, 0, 100, 0, 5, 1, 50where the last 7 params are the values of the Public Types enums. QFontMetrics::width() returns 201.
After re-selecting the same font from a QFontDialog I get:
Font family Comic Sans MS, point size 10, word spacing 0.000000, letter spacing 0.000000, kerning 1, pixel size -1, fixed pitch 0, params 0, 0, 100, 0, 5, 1, 50
which looks exactly the same, but this time the width value is 273 which appears to be correct. I've tried this with several different fonts with the same result.
What could explain the difference?
Alan