[PyKDE] qRgb and distribution

Phil Thompson phil at river-bank.demon.co.uk
Wed Nov 22 11:01:05 GMT 2000


Philippe Fremy wrote:
> 
>         Hi,
> 
> I don't know if this is fixed in PyQt 2.2, but in PyQt 2.1, the qRgb() function
> and the QColor::rgb() function which are both supposed to return a QRgb value
> are not consistent:
> 
> >>> qRgb(0,0,0)
> -16777216
> >>> col = QColor(0,0,0)
> >>> col
> <qt.QColor instance at 8111dc0>
> >>> col.rgb()
> (0, 0, 0)
> 
> The enum is a good idea but I still prefer the int value.  And since QRgb is a
> typedef int, I would have expected its value to be 0 for (0,0,0).

It's a little bit more complicated. In Qt there is "void QColor::rgb(int
*,int *,int *)" and "QRgb QColor::rgb()". Python doesn't have pointers
to the first method is implemented to return the 3 int values as a
tuple. Unfortunately this means that the two methods now have identical
argument signatures (they both take no arguments) and means that the
second method (the one you want to use) can never be called.

The solution is to give one of the methods a different name in PyQt (eg.
call the first one rgb_tuple()), but this will potentially break
existing scripts.

> Last thought: Is there a PyQt program repository ? That would help in code
> sharing and advertising. The PyQt homepage looks like a good place for this,
> no ?

I'm happy to have the information included on the homepage if somebody
wants to collect it.

Phil




More information about the PyQt mailing list