Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Different font pixel metrics in different devices.



  • Hi!

    When I execute this code in Windows

        QFont f = QFont("Verdana");
        f.setPixelSize(18);
        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?

    thanks!!

    Xavierll


Log in to reply