[PyQt] QtGui.QColor.fromRgb()

Aron Bierbaum aronbierbaum at gmail.com
Tue Feb 16 16:08:12 GMT 2010


Thanks for the quick response. It took me a while to track through
exactly why this works. I guess the key is that on 32-bit platforms
the return value of the bitwise and is a long instead of a integer.

Thanks,
Aron

On Mon, Feb 15, 2010 at 9:07 PM, Phil Thompson
<phil at riverbankcomputing.com> wrote:
> On Mon, 15 Feb 2010 17:19:16 -0600, Aron Bierbaum <aronbierbaum at gmail.com>
> wrote:
>> I have attached a test that shows a possible regression in
>> QtGui.QColor.fromRgb() PyQt 4.7. In past releases we have been able to
>> get the color the grid lines in a table from the current style and
>> convert it to a QColor. For some reason PyQt raises a TypeError
>> exception:
>>
>> Raw color: -2565928
>> Traceback (most recent call last):
>>   File "test_fromrgb.py", line 7, in <module>
>>     color = QtGui.QColor.fromRgb(raw_color)
>> TypeError: arguments did not match any overloaded call:
>>   QColor.fromRgb(int): argument 1 has unexpected type 'int'
>>   QColor.fromRgb(int, int, int, int alpha=255): not enough arguments
>>
>> Is this a valid use of the method, and if so any ideas what is going
> wrong?
>
> I don't think it is a regression - maybe you are just now seeing values
> that cause a problem?
>
> The problem is that C++ is returning an unsigned value with the high bit
> set as an int. Python then assumes it is negative, but fromRgb() is
> expecting an unsigned (ie. positive) value.
>
> Just make sure that raw_color is unsigned before you use it...
>
> raw_color &= 0xffffffff
>
> Phil
>


More information about the PyQt mailing list