Qt/ Qml Frobihser font behaving differently in Linux and Windows environment

118 Views Asked by At

I have written a qtquickapplication sample program to display a text "none" within given rectangle. Rectangle border color is set to red to visualize whether text "none" is fitting properly within given width and height or not.

I have compiled same program for windows and Linux environment separately. I am stuck with strange behavior.

With the same code and font (Frobisher), the text "none" is fitting properly inside rectangle boundary but it's truncating in Windows environment.

What's reason for it? Why font is behaving differently? Did I miss anything?

Qt Linux environment output Qt Windows environment output

main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtFontDatabaseSupport/QtFontDatabaseSupport>

int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

QGuiApplication app(argc, argv);

QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));

QFontDatabase::addApplicationFont("FrobisherNormal.ttf");

engine.load(url);

return app.exec();
}

main.qml

import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 2.14
Window {
visible: true
width: 300
height: 200
title: qsTr("Hello World")

Rectangle
{
    width: 65
    height: 32
    border.color: "red"
    anchors.centerIn: parent

    Text {
        id: txt
        text: "none"
        font.family: "Frobisher"
        font.pointSize: 20
        font.bold: false
        anchors.verticalCenter: parent.verticalCenter
        verticalAlignment: "AlignVCenter"
    }
}
}
1

There are 1 best solutions below

0
On

Make sure you have the font in both system. At least check the return value of addApplicationFont.

Using pixelSize instead pointSize might be helpful.