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. Apparent inconsistency with QFontMetrics::width()
Forum Updated to NodeBB v4.3 + New Features

Apparent inconsistency with QFontMetrics::width()

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.0k 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.
  • I Offline
    I Offline
    Inchiquin
    wrote on last edited by
    #1

    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, 50

    where 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

    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