【发布时间】:2019-03-11 00:32:09
【问题描述】:
虽然以下代码适用于桌面 Linux 和 Windows,但在嵌入式 linux(yocto jethrow、Qt 5.5.1、Qt on X11)上,中文字符显示为空白。似乎 Qt 使用它自己的字体,而不是这个系统上的系统字体。注意:“Hello World”后面应该有中文“你好”。
main() 的 C++ 内容:
QApplication a( argc, argv );
QString s = QString::fromUtf8("Hello world \u611b!");
QPushButton hello;
// eventually set font here, see below
hello.setText(s);
hello.resize( 200, 30 );
hello.show();
return a.exec();
在另一个使用 Qt 4 的嵌入式系统上,只需安装正确的字体就足够了。字体也在这里正确安装并被 fc-list 识别。
如果我修改上面的代码并直接设置字体,它会按预期工作:
// insert font here:
int id = QFontDatabase::addApplicationFont("/usr/share/fonts/wqy/wqy-microhei.ttc");
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
QFont font(family);
hello.setFont(font);
// end modification
hello.setText(s);
如果我制作一个简单的 qml 脚本,我还必须设置字体。 但是,如果我使用网络引擎浏览器小部件,它可以显示中文字符。
命令“fc-list”(liberation, wqy-microhei)和qt函数“Qt.fontFamilies()”(bitstream, luxi, dejavu, curier, cursor, utopia)显示的字体是不同的.
是否可以在不重新编译qt或应用程序的情况下更改qt配置,以便将wqy-microhei用于汉字?
【问题讨论】: