[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] QColorDialog: saving custom colors on Mac
From:       Phil Thompson <phil () riverbankcomputing ! com>
Date:       2011-07-29 17:12:32
Message-ID: 5c3963a694d29e7c5e8ffcaa3d73d124 () localhost
[Download RAW message or body]

On Mon, 18 Jul 2011 12:06:05 -0400, Nathan Weston <nathan@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.

> Related to this, when you pass a negative int to 
> QColorDialog.setCustomColor(), it throws this rather baffling exception:
>    TypeError: QColorDialog.setCustomColor(int, int): argument 2 has 
> unexpected type 'int'
> 
> It seems like ValueError would be more appropriate. At the very least, a

> more accurate error message would have saved me about 20 minutes of 
> scratching my head. :)

It's actually an overflow. In tonight's SIP snapshot I've switched to
using PyLong_AsUnsignedLongMask() which ignores overflows. SIP ignores
overflows anyway when converting to small C++ types (eg. short) so this
makes the behavior more consistent and means that you can pass -1 in the
call above.

Phil
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic