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 does not account for windows dpi scaling
Qt 6.11 is out! See what's new in the release blog

QFontMetrics does not account for windows dpi scaling

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 582 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.
  • M Offline
    M Offline
    Milo
    wrote on last edited by Milo
    #1

    when changing dpi scaling from 100% to 200% in Windows 10, i expect the following string to be twice as wide.

    QFont font = QFont("arial", 10);
    QFontMetrics fm(font);
    int width = fm.width("abcdefgABCDEFG");
    

    Strangely there is only 1 pixel difference.

    100% --> width = 108 pixels
    200% --> width = 109 pixels

    Why is that? Do I need to compute the scaled size of the text myself?
    I did enable automatic high DPI scaling in my QApplication.

    QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QApplication* app = new QApplication(temp, NULL);
    

    Thanks

    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