How to display international scripts in QLabels?

别来无恙 提交于 2019-12-13 15:50:51

问题


I would like to display Indic, Arabic and Hebrew scripts in a QLabel, specifying the font type. When I try to pass a UTF-8 encoded string into a QLabel, the script is not rendered properly.

What is the correct way to display international (non-alphabetic) scripts in a QLabel?


回答1:


Setting the text of a QLabel to a unicode string (unicode in python2, str in python3) should work fine.

In python2 you can use QString.fromUtf8 to convert a utf8-encoded str to an unicode QString, or .decode('utf-8') to a python unicode.

In PyQt4 on python3 QString is gone as now str is already unicode, so just use that.

For instance:

    s = "اردو"
    d = s.decode('utf-8')
    label = QtGui.QLabel(d)
    font = QtGui.QFont("Sheherazade", 40)
    label.setFont(font)


来源:https://stackoverflow.com/questions/11575533/how-to-display-international-scripts-in-qlabels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!