[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

help! PyQt4 and UTF-8

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)
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)
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 PyQt examples
use "Arial." I've also tried "FixedSys Excelsior 3.01".

Python version: CPython 2.7.14
OS: Windows 10

thanks for any help