[PyQt] trouble displaying unicode

Maurizio Berti maurizio.berti at gmail.com
Sat Aug 18 04:56:14 BST 2018


I just tried your example using decode(), and it works fine on Linux.
I got the infamous square when using with Wine, though; the same happens
when I just paste the correctly encoded text (copied from the linux-run
test), so I don't know if it's only a Wine issue, but you could try the
same and see if the unicode character shows up.
If that's the case, you should consider using encoded unicode strings by
default ( u'unicode string' ) or, maybe, using QString.fromUtf8 if you're
still using QString v1 api.
If the character doesn't show up instead, it might be a font issue (I don't
know much about font handling on windows, maybe you should specify a
different family?).

MaurizioB

Il giorno sab 18 ago 2018 alle ore 01:51 inhahe <inhahe at gmail.com> ha
scritto:

> 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!
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt



-- 
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180818/1b1de8d7/attachment-0001.html>


More information about the PyQt mailing list