[PyQt] QColorDialog: saving custom colors on Mac

Nathan Weston nathan at genarts.com
Mon Aug 8 14:12:50 BST 2011


On 7/29/2011 1:12 PM, Phil Thompson wrote:
> On Mon, 18 Jul 2011 12:06:05 -0400, Nathan Weston<nathan at genarts.com>
> wrote:
>> I'm trying to save the custom colors of QColorDialog using QSettings. On
>
>> Windows this is working correctly, but on Mac I'm having some problems:
>>
>> 1. QColorDialog.customColor() returns a long instead of an int
>> 2. When I save that long using QSettings, it comes back as an int with a
>
>> value of -1
>>
>> This seems like a bug in Qt or PyQt to me. Am I missing something?
>
> It's the usual problem with QSettings not being able to restore the value
> exactly because it doesn't retain sufficient type information. In this case
> the fact that the value is unsigned and not signed (the bit pattern is the
> same).
>
> You should always use the 'type' keyword argument to QSettings.value() to
> explicitly state what you are expecting back. As Python doesn't have an
> unsigned type you have to specify a C++ type...
>
>      settings.value('color', type='uint')
>
> ...should work.
>

What if I'm retrieving a list of unsigned ints? What's the correct type 
signature?

I'm using the v2 QVariant API so I just collected all the custom colors 
into a python list and saved that.

-- 
. . . . . . . . . . . . . . . . . . . . . . . . .
Nathan Weston                   nathan at genarts.com
GenArts, Inc.                   Tel: 617-492-2888
955 Mass. Ave                   Fax: 617-492-2852
Cambridge, MA 02139 USA         www.genarts.com


More information about the PyQt mailing list