Qt-interest Archive, January 2008
Opacity in QPainter::drawImage()
Message 1 in thread
I have implemented a system for draw in a QGraphicsView with a pencil, like Gimp or Paint.
I have created a class derived from QGraphicsItem. This class contain a QImage object. When user draws on screen, in my implementation, I draw on the QImage object. In the paint method of my GraphicsItem I simply call QPainter::drawImage().
Now I want to modify the opacity of the drawings, so I do this:
painter->setOpacity(opacity);
painter->drawImage(QPoint(0, 0), image);
painter->setOpacity(1.0);
This works only if my GraphicsItem is not transfomed. If my item is trasformed (e.g. when I want to zoom) the drawings is completely opaque.
I have seen that I can fix it doing this:
painter->setOpacity(opacity);
painter->drawPixmap(QPoint(0, 0), QPixmap::fromImage(image));
painter->setOpacity(1.0);
but it is obviously very slow. But I can't use directly a QPixmap because I can't draw in a QPixmap, but only in a QImage. If I create a QPixmap from a QImage everytime the user draws, the drawing become too slow.
How can I solve this problem?
--
[ signature omitted ]