在 Windows 上初次使用 Qt Creator 就觉得外观字体显示很不友好,就想着在注册列表中修改 Windows 系统的默认字体,但是不知道 Qt Creator 使用到了哪些字体。
通过查看Qt Creator源码,在qtbase\src\platformsupport\fontdatabases\windows\qwindowsfontdatabase.cpp 文件中看到下面的代码:
QFont QWindowsFontDatabase::systemDefaultFont() { #if QT_VERSION >= 0x060000 // Qt 6: Obtain default GUI font (typically "Segoe UI, 9pt", see QTBUG-58610) NONCLIENTMETRICS ncm; ncm.cbSize = FIELD_OFFSET(NONCLIENTMETRICS, lfMessageFont) + sizeof(LOGFONT); SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize , &ncm, 0); const QFont systemFont = QWindowsFontDatabase::LOGFONT_to_QFont(ncm.lfMessageFont); #else LOGFONT lf; GetObject(QWindowsFontDatabase::systemFont(), sizeof(lf), &lf); QFont systemFont = QWindowsFontDatabase::LOGFONT_to_QFont(lf); // "MS Shell Dlg 2" is the correct system font >= Win2k if (systemFont.family() == QLatin1String("MS Shell Dlg")) systemFont.setFamily(QStringLiteral("MS Shell Dlg 2")); // Qt 5 by (Qt 4) legacy uses GetStockObject(DEFAULT_GUI_FONT) to // obtain the default GUI font (typically "MS Shell Dlg 2, 8pt"). This has been // long deprecated; the message font of the NONCLIENTMETRICS structure obtained by // SystemParametersInfo(SPI_GETNONCLIENTMETRICS) should be used instead (see // QWindowsTheme::refreshFonts(), typically "Segoe UI, 9pt"), which is larger. #endif // Qt 5 qCDebug(lcQpaFonts) << __FUNCTION__ << systemFont; return systemFont; }未来 Qt 6 会使用Windows10的默认字体,在 Qt 5 及更低的版本上还是使用的 MS Shell Dlg 和 MS Shell Dlg 2 字体。
找到Qt Creator 使用到的字体后,进入注册表(win+r > regedit),找到 计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes 修改 MS Shell Dlg 和 MS Shell Dlg 2的数值数据为Microsoft YaHei UI(任意个人喜好的字体): 数值数据在计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts列表中。
进入到计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\GRE_Initialize: 将GUIFont.Facename的数值数据改为Microsoft YaHei UI: 重启电脑后,再次打开 Qt Creator 外观是不是变得很友好了。