[PyQt] QtGui.QColor.fromRgb()

Phil Thompson phil at riverbankcomputing.com
Tue Feb 16 03:07:52 GMT 2010

On Mon, 15 Feb 2010 17:19:16 -0600, Aron Bierbaum <aronbierbaum at gmail.com>
> 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

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


More information about the PyQt mailing list