简体   繁体   English

Qt/Qml Frobihser 字体在 Linux 和 Windows 环境中的行为不同

[英]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.我编写了一个 qtquickapplication 示例程序来在给定的矩形内显示文本“无”。 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.我分别为 Windows 和 Linux 环境编译了相同的程序。 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.使用相同的代码和字体 (Frobisher),文本“无”在矩形边界内正确匹配,但在 Windows 环境中被截断。

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 .至少检查addApplicationFont的返回值。

Using pixelSize instead pointSize might be helpful.使用pixelSize替代的pointsize可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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