如何为跨平台 Qt 应用程序指定等宽字体? [英] How to specify monospace fonts for cross platform Qt applications?
本文介绍了如何为跨平台 Qt 应用程序指定等宽字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有独立于平台的方式来为 Qt 小部件指定固定宽度的字体?
Is there a platform independent way to specify a fixed width font for a Qt widget ?
如果我在 Linux 上的 Designer 中将字体设置为等宽",则在 Windows 上找不到它,而是使用 Arial.
If I set the font to "Monospace" in Designer on Linux, it is not found on Windows and Arial is used instead.
推荐答案
您可以使用 QFontDatabase 的 systemFont(..) 函数检索系统默认的固定字体.它是在 Qt 5.2 中引入的.
You can retrieve the system's default fixed font using QFontDatabase's systemFont(..) function. It was introduced in Qt 5.2.
示例:
const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont)
这篇关于如何为跨平台 Qt 应用程序指定等宽字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文