[PyQt] Fwd: Re: Weird QTextLabel Output

Henrik Pauli henrik.pauli at gmail.com
Sat Apr 24 04:09:33 BST 2010


2010-04-24 04:45 keltezéssel, matt-lists at comnet.net.nz írta:
> On Saturday 24 April 2010 14:09:44 Henrik Pauli wrote:
>> 2010-04-24 03:02 keltezéssel, matt-lists at comnet.net.nz írta:
>>> I've got a small program that parses a web page and outputs a small
>>> amount of text to a QTextLabel.  The problem is, that when displaying
>>> numbers with spaces between them, the textLabel seems to add in strange
>>> characters. Example:  http://everydaylht.com/example.png
>>>
>>> The string should be "6 272 640 square inches".  This is how the string
>>> looks when I parse the webpage.  If I print the string before it is
>>> displayed, the terminal output is how it should be (ie. 6 272 640 square
>>> inches).  However, in a QTextLabel, those weird A's get inserted.
>>
>> What you see there is non-breaking spaces (finally someone properly
>> typesetting them numbers!).  They should appear as normal spaces, but
>> for some reason, the fact that you're dealing with a UTF-8 text doesn't
>> really seem to reach Python's or PyQt's mind.
>>
>>> The source file uses UTF-8 encoding.
>>>
>>> Any suggestions what this might be, or how it might be fixed.
>>
>> Maybe try to .decode that string as UTF-8 to get a unicode object which
>> then you feed to the QTextLabel?
>
> Are you able to give me a hint how to do that.  I've been playing with .decode
> and .encode and really am struggling with what I'm doing.

Is there a reason you str() that match there in line 6?  If it works 
without it, keep it str()-less :)  Otherwise, I think I'd do the 
following in line 16:

self.f.label.setText(q_result.decode("utf-8"))



I really hope that's syntactically correct, I haven't touched Python in 
quite a long time unfortunately.


More information about the PyQt mailing list