我想在 QLabel 中显示印度语、阿拉伯语和希伯来语脚本,并指定字体类型。当我尝试将 UTF-8 编码的字符串传递到 QLabel 中时,脚本未正确呈现。
在 QLabel 中显示国际(非字母)脚本的正确方法是什么?
最佳答案
将QLabel
的文本设置为unicode字符串(python2中的unicode
,python3中的str
)应该可以正常工作。
在python2中,您可以使用QString.fromUtf8
将utf8编码的str
转换为unicode QString
,或.decode ('utf-8')
到 python unicode
。
在 python3 上的 PyQt4 中,QString
已经消失,因为现在 str
已经是 unicode,所以只需使用它。
例如:
s = "اردو"
d = s.decode('utf-8')
label = QtGui.QLabel(d)
font = QtGui.QFont("Sheherazade", 40)
label.setFont(font)
关于string - 如何在QLabels中显示国际脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11575533/