Important: Please read the Qt Code of Conduct -

Different font pixel metrics in different devices.

  • Hi!

    When I execute this code in Windows

        QFont f = QFont("Verdana");
        QFontMetrics fm(f);
        int pixelsWidth = fm.width("What's the width of this text?What's the width of this text?");
        int pixelsHeight = fm.height();
        qDebug() << "Width: " << pixelsWidth;
        qDebug() << "Height: " << pixelsHeight;

    I Obtain:

    Width: 528;
    Height: 22;

    When executed on Android:

    Width: 458
    Height: 21

    If I load the font as a ".ttf"

    fontId = QFontDatabase::addApplicationFont(":/fonts/verdana/verdana");

    On windows I get:

    Width: 528
    Height: 22

    On Android:

    Width: 534
    Height: 22

    Is Qt using a different font rendering engine for different platforms? Is there any way to obtain the same pixel size for both devices?



Log in to reply