Qt标题栏中文乱码,qml标题栏中文乱码问题,openbox支持中文

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mynameislinduan/article/details/84791733

qt5标题栏中文问题,qml标题栏

一、 确定错误位置

  • 项目中遇到一个怪异的问题,qml写的程序,弹出的对话框,对话框内容非常正常,中英文都ok,但是对话框的tiltle标题栏,显示的却是乱码。甚是怪异!我的项目是嵌入式系统,arm + Debian Fs + X11+ Qt5 + openbox;

  • 网搜索了一堆,都是qt4如何如何支持中文的文章,并不是qt5,必应搜索一阵子找到qt5中文问题的解决方法,变实测边做,最后发现,但是不是这个问题

  • 然后找比较熟悉qt的同事的请教,也是一脸懵。接着怀疑是linux 系统的locale问题,接着马上折腾locale,也没啥卵用。

  • 后来主管提示了一下,应该是Openbox的问题,因为标题栏不是qt画的,应是openbox画的。有道理!于是去查openbox的问题,bing/google之后,发现openbox的rc.xml是我要找的配置文件,
    ~/.config/openbox/rc.xml

二、排查错误

在xml的配置文件rc.xml中,搜寻关键字font,果然发现了数个关于font的描述:

	    <font place="ActiveWindow">
      <name>sans</name>
      <size>8</size>
      <!-- font size in points -->
      <weight>bold</weight>
      <!-- 'bold' or 'normal' -->
      <slant>normal</slant>
      <!-- 'italic' or 'normal' -->
    </font>
    <font place="InactiveWindow">
      <name>sans</name>
      <size>8</size>
      <!-- font size in points -->
      <weight>bold</weight>
      <!-- 'bold' or 'normal' -->
      <slant>normal</slant>
      <!-- 'italic' or 'normal' -->
    </font>
    <font place="MenuHeader">
      <name>sans</name>
      <size>9</size>
      <!-- font size in points -->
      <weight>normal</weight>
      <!-- 'bold' or 'normal' -->
      <slant>normal</slant>
      <!-- 'italic' or 'normal' -->
    </font>
    <font place="MenuItem">
      <name>sans</name>
      <size>9</size>
      <!-- font size in points -->
      <weight>normal</weight>
      <!-- 'bold' or 'normal' -->
      <slant>normal</slant>
      <!-- 'italic' or 'normal' -->
    </font>
    <font place="ActiveOnScreenDisplay">
      <name>sans</name>
      <size>9</size>
      <!-- font size in points -->
      <weight>bold</weight>
      <!-- 'bold' or 'normal' -->
      <slant>normal</slant>
      <!-- 'italic' or 'normal' -->
    </font>
    <font place="InactiveOnScreenDisplay">
      <name>sans</name>
      <size>9</size>
      <!-- font size in points -->
      <weight>bold</weight>
      <!-- 'bold' or 'normal' -->
      <slant>normal</slant>
      <!-- 'italic' or 'normal' -->
    </font>

明显,这个配置文件指定了openbox使用一个字体文件,叫san,什么玩意?? 不懂,只能搜索系统,先用 find / -name “san” , 结果一大堆,根本无法辨认,于是我打算先用apt get装一个字体,看看字体放在哪里。网上捣鼓一番,发现了: fc-list 和 fc-cache两个有用的命令,是用来处理字体的,一个是显示当前系统的字体有哪些,叫什么名字,一个是更新当前系统字体缓存。安装中文字体:


# apt-get install xfonts-wqy ttf-wqy-zenhei ttf-wqy-microhei 

三、修改更正

之后, 用fc-list,发现我们安装的字体了。知道我们装的字体,在 /usr/share/fonts/ … 里面,于是对比 原来的rc.xml文件,和新安装的中文字体,我改了rc.xml的名字( sans 改成 Micro Hei )

vi ~/.config/openbox/rc.xml

然后保存从新启动系统,发现标题栏显示非常正常, 这个问题解决了。

猜你喜欢

转载自blog.csdn.net/mynameislinduan/article/details/84791733