[PyQt] trouble displaying unicode

inhahe inhahe at gmail.com
Sat Aug 18 00:50:32 BST 2018


I can display UTF-8 when I use wxPython:
------
import wx
app = wx.App()
s = 'testing\xf0\x9f\x98\x80'
frame = wx.Frame(None, wx.ID_ANY)
font = wx.Font("Arial")
textbox = wx.TextCtrl(frame, id=wx.ID_ANY)
textbox.SetFont(font)
textbox.WriteText(s)
frame.Show()
app.MainLoop()
------
But when I try the same thing with PyQt4..
------
from PyQt4 import QtGui
import sys
s = 'testing\xf0\x9f\x98\x80'
app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
font = QtGui.QFont("Arial")
textbox = QtGui.QLineEdit(w)
textbox.setFont(font)
textbox.setText(s)
w.show()
sys.exit(app.exec_())
------
Instead of "testingšŸ˜€" ("testing" with a smiley face after it, if you can't
see it in this message), I get "testingĆ°" ("testing", then an o with some
kind of mark above it).

I tried replacing
------
s = 'testing\xf0\x9f\x98\x80'
------
with
------
s = 'testing\xf0\x9f\x98\x80'.decode('UTF-8')
------
in case PyQt takes Unicode instead of UTF-8, but in that case I get
"testing" and then a little square after it (like the character isn't found
in the font). If I copy it and paste it here I get "testingšŸ˜€" ("testing"
with a smiley face after it, like I want), so I guess displaying it in the
font is the problem, but I don't know why.. as you can see, both the
wxPython and the PyQt4 programs use "Arial". I've also tried "FixedSys
Excelsior 3.01".

Python version: CPython 2.7.14
OS: Windows 10

thanks for any help!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180817/ed290cfa/attachment.html>


More information about the PyQt mailing list