[PyKDE] Strange QColor behavior when passing rgb in constructor.

Truls A. Tangstad kerfue+pykde at herocamp.org
Wed Mar 9 12:16:49 GMT 2005


I've been testing and debugging to find a problem in our code where
plots just weren't drawn (or rather drawn in white on white
background), which I finally tracked down to be the way I used QColor.

I assumed that passing a combined rgb-value as an int to QColor()
would create the right color according to [1], but I kept getting
white, no matter what rgb value I set. What was even stranger was that
the  QColor-methods red(), green() and blue() returned the correct
value for the created QColor-instance.

I found that the problem was the default value for the pixel-parameter
(documented in [1] to be pixel=0xffffffff).  When setting the value to
-1 or 0xffffffff explicitly, everything worked fine. When omitting it,
the color displayed as white (might be specific to my system).

Also, creating an empty QColor, then setting rgb with setRgb() works
fine.

I created a small example (attached) showing the problem, creating two
QMainWindows that should be painted red, but for me displays as one
white and one red. A C++ port of the code did not have the bug.

My software versions are as follows (running debian unstable):
python2.3-qt3       3.13-4
libqt3c102-mt       3.3.3-8
libqt3c102          3.3.3-8

And yes.. I know this is really a minor issue, as I can easily work
around it, but I hope that fixing the problem will keep others from
spending as much time as I did to try to figure out why their code
misbehaves.

[1] - http://doc.trolltech.com/3.3/qcolor.html#QColor-4

-- 
Truls A. Tangstad - <kerfue+pykde at h e r o c a m p.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: colortest.py
Type: text/x-python
Size: 282 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20050309/374fbbe9/colortest.py


More information about the PyQt mailing list