[PyKDE] C++ to Python Datatypes

Russell Valentine russ at coldstonelabs.org
Tue Oct 14 05:32:01 BST 2003

On Sun, 12 Oct 2003 22:25:59 -0700
Jim Bublitz <jbublitz at nwinternet.com> wrote:

> Here is the method referenced from the PyQt docs:
> """
> QImage(uchar *data, int w, int h, int depth, QRgb *colorTable,  
>      int numColors, Endian bitOrder);
> The colorTable parameter is a list of QRgb instances or None. (Qt 
> v2.1+)
> """
> This probably won't clarify the uchar* parameter for you, but it 
> does indicate that the QRgb* parameter is a Python list of
> QRgb instances or None.

Thanks for your help.

I did notice that documentation. However I though QColor(value, value,
value).rgb() would return a QRgb instance. I notice this also in the

void rgb(int *r, int *g, int *b);

This takes no parameters and returns the r, g and b values as a tuple.

So does this mean the

QRgb QColor::rgb () const 

function is not implemented because void rgb(int *r, int *g, int *b) which
takes no parameters takes over instead?

I try the following:

grayColorMap = []
for i in range(256):
    grayColorMap.append(qRgb(i, i, i))

grayColorMap = []
for i in range(256):
    grayColorMap.append(QColor(i, i, i).rgb())

It likes the first one, but not the second one. It gives.

Traceback (most recent call last):
  File "./testQColor.py", line 21, in ?
    image = QImage(buffer, 2, 2, 8, grayColorMap, 256, QImage.IgnoreEndian)
  File "/usr/lib/python2.2/site-packages/qt.py", line 439, in __init__
TypeError: an integer is required

I must admit that qRgb(r,g,b) is better than making a QColor(r,g,b) and
calling rgb() on it, so it isn't that big of a deal for me at the moment.

Russell Valentine
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20031014/c8a5ce76/attachment.bin

More information about the PyQt mailing list