简体   繁体   中英

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

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 环境输出 Qt Windows 环境输出

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"
    }
}
}

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

Using pixelSize instead pointSize might be helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM