繁体   English   中英

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

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

我编写了一个 qtquickapplication 示例程序来在给定的矩形内显示文本“无”。 矩形边框颜色设置为红色以可视化文本“无”是否在给定的宽度和高度内正确拟合。

我分别为 Windows 和 Linux 环境编译了相同的程序。 我被奇怪的行为困住了。

使用相同的代码和字体 (Frobisher),文本“无”在矩形边界内正确匹配,但在 Windows 环境中被截断。

这是什么原因? 为什么字体表现不同? 我错过了什么吗?

Qt Linux 环境输出 Qt Windows 环境输出

主程序

#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();
}

主文件

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

确保您在两个系统中都有该字体。 至少检查addApplicationFont的返回值。

使用pixelSize替代的pointsize可能会有所帮助。

暂无
暂无

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

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