如何为跨平台的Qt应用程序指定等宽字体? [英] How to specify monospace fonts for cross platform Qt applications?

查看:869
本文介绍了如何为跨平台的Qt应用程序指定等宽字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果我在Linux的Designer中将字体设置为Monospace,那么它是一种独立于平台的方式来指定一个固定宽度的字体在Windows上找不到,Arial被用来代替。

解决方案

你可以使用QFontDatabase的systemFont检索系统的默认固定字体。 )功能。
它是在Qt 5.2中引入的。
$ b $例子:

  const QFont fixedFont = QFontDatabase :: systemFont(QFontDatabase :: FixedFont)


Is there a platform independent way to specify a fixed width font for a Qt widget ?

If I set the font to "Monospace" in Designer on Linux, it is not found on Windows and Arial is used instead.

解决方案

You can retrieve the system's default fixed font using QFontDatabase's systemFont(..) function. It was introduced in Qt 5.2.

Example:

const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont)

这篇关于如何为跨平台的Qt应用程序指定等宽字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆