help wanted regarding displaying Japanese characters in a GUI using QT and python

David Boddie david at boddie.org.uk
Wed Apr 19 11:33:33 EDT 2006


[Posting via Google's web interface again and hoping that double
newlines will prevent insane concatenation of lines...]


prats wrote:


> I want to write a GUI application in PYTHON using QT. This application
> is supposed to take in Japanese characters. I am using PyQt as the
> wrapper for using QT from python. I am able to take input in japanese.
> But I am unable to display them back to GUI. It displays some junk
> characters Can anyone suggest me some way how to debug the issue.


> The code used for tranferring data from view to document is:


> "
> codec = QTextCodec.codecForName('ISO-2022-JP')
> encoded_string = codec.fromUnicode( string )
> return str(encoded_string)
> "


> here string is QString object containing the data from the view.
> I think the encoded_string is a QCString object and contains the
> unicode coded characters of the japanese string given in the GUI?


Actually, it contains the original text in the ISO-2022-JP encoding and
not a unicode representation. You're just storing an anonymous sequence
of characters in your encoded_string variable which you then return.
Any
user interface element that receives these later on has to guess which
encoding is used to represent the text, and it sounds like it can't do
that.


> how am I going to display the data back to the view from document.


If you're using the text in the GUI, you shouldn't need to pass it
through the codec at all. It should be possible to display the original
string in any widget that can display text. Keep the text in a QString
and
it should just work.


David




More information about the Python-list mailing list