Important: Please read the Qt Code of Conduct -

QFontMetrics does not account for windows dpi scaling

  • 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.

    QApplication* app = new QApplication(temp, NULL);


Log in to reply