I am trying to make some pixels semi-transparent.
Using a QPainter with pen color Qt::color0 and Qt::color1 works to make pixels fully transparent or opaque, but I tried to set the pen color to 0.5 to make a partially transparent pixel, but it does not work as I would expect.
In this example, the opaque pixels are red, the transparent pixels are white (the color of the background, and I would expect the semitransparent pixels to be pink, but they are also white:
http://programmingexamples.net/index.php?title=Qt/Images/SemiTransparentPixels
Can anyone see where I have gone wrong?
painter.setPen(.5);
is probably not doing what you expect it to do. You need to do something likepainter.setPen( QColor( 255, 0, 0, 127 ) );
like Stephen Chu suggested – Tim Meyer