[PySide] trouble with special characters in widget.setToolTip()
Frank Rueter | OHUfx
frank at ohufx.com
Fri Mar 4 06:19:35 CET 2016
Ah, thanks Dan and Luc for clarifying. I thought I was passing a unicode
string when I started messing around with it but obviously I wasn't.
It's all working as expected now, thank you all!
frank
On 4/03/16 5:01 am, Luc-Eric Rousseau wrote:
> That reply from Dan was the correct answer.
>
> The reason why the string prints correctly in a console-like UI is
> because these UI typically
> expect stings to be UTF-8 and that chunk of bytes you pass it is a
> valid UTF-8 string.
>
> However Qt thinks that chunk of 8 bit character from python is Latin-1
>
> If you made your python string unicode like this, both cases would work
>
> myText = u'special charactes cause headaches: {}'.format(quotationMark)
>
> it's probably going to work fine also in that other host you use which
> has set the default
> 8-bit encoding of Qt to Utf-8, because no encoding will take place.
>
> On 3 March 2016 at 03:52, Dan Milburn <milburn at thefoundry.co.uk> wrote:
>> Hi,
>>
>> It's not anything to do with the font.
>>
>> Qt uses 16-bit unicode strings internally. If you give a str to a PySide
>> function, it will need to decode it, and by default it will probably treat
>> it as ASCII. If you want Qt to assume 8-bit strings are UTF-8 encoded, you
>> can use the following:
>>
>> from PySide.QtCore import QTextCodec
>>
>> QTextCodec.setCodecForCStrings(QTextCodec.codecForName("UTF-8"))
>>
>>
>> However it would be better practice to pass it unicode strings if you can.
>>
>>
>> Dan
>>
>>
>>
>> On 3 March 2016 at 00:45, Frank Rueter | OHUfx <frank at ohufx.com> wrote:
>>> Thanks guys.
>>>
>>>>> That would imply that your tooltip uses a different default font.
>>> Aha, that makes perfect sense, thank you!
>>> I'm currently on OSX using Wing as my IDE. When I ran this code inside a
>>> host application, it worked fine (because it changes the default font).
>>> I will verify that though before moving on. Text encoding/decoding always
>>> confuses me (I hardly have to deal with it, so there is no routine) and I
>>> want to get it right this time.
>>>
>>> Cheers,
>>> frank
>>>
>>>
>>> On 03/03/2016 06:26 AM, Tim Roberts wrote:
>>>
>>> Sebastian Elsner | RISE wrote:
>>>
>>> Unicode is tricky, it bites me every time. This works:
>>>
>>>
>>> It's not that hard. There are two possibilities. Either the setTool
>>> function does not accept Unicode strings, or the default tool tip font does
>>> not include those extended characters.
>>>
>>>
>>> Please note, the .py file actually has to be saved/encoded as utf-8. You
>>> need to do this via your editor's save/convert function.
>>>
>>>
>>> Actually, it doesn't. There are no characters in his file beyond the base
>>> ASCII set, except for the one character in a comment, so the file coding is
>>> irrelevant. If this worked for you, then his original code would have
>>> worked for you also. That would imply that your tooltip uses a different
>>> default font. No one here has mentioned what operating systems they are
>>> using; that makes a difference.
>>>
>>> --
>>> Tim Roberts, timr at probo.com
>>> Providenza & Boekelheide, Inc.
>>>
>>>
>>>
>>> _______________________________________________
>>> PySide mailing list
>>> PySide at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>>
>>>
>>>
>>> _______________________________________________
>>> PySide mailing list
>>> PySide at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/pyside
>>>
>>
>>
>> --
>> Dan Milburn
>> Software Engineer - Nuke
>> The Foundry
>> 5 Golden Square
>> London
>> W1F 9HT
>> Tel: +44(0) 20 7479 4350 • Fax: +44 (0)20 7434 2526 • Web:
>> http://www.thefoundry.co.uk
>>
>> The Foundry Visionmongers Ltd.
>> Registered in England and Wales No: 4642027
>>
>>
>>
>>
>> _______________________________________________
>> PySide mailing list
>> PySide at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/pyside
>>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
--
ohufxLogo 50x50 <http://www.ohufx.com> *vfx compositing
<http://ohufx.com/index.php/vfx-compositing> | *workflow customisation
and consulting <http://ohufx.com/index.php/vfx-customising>* *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20160304/2f25c2a5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ohufxLogo_50x50.png
Type: image/png
Size: 2666 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20160304/2f25c2a5/attachment.png>
More information about the PySide
mailing list