Image composition with QWidget as a painting device.
skrech last edited by skrech
I'm trying to make a slider with custom look. The slider is just QWidget with custom logic and overriden paintEvent. It consists of 3 pixmaps:
Transparent pixmap with small frame and shadow on it, which I'll use for basis of my composition:
Inner handle that should receive the shadow effect from the previous pixmap.
Outer handle that should be absolutely opaque.
The net effect that I want to achieve is this:
(the background of the whole composition should be transparent, but the site that I uploaded the picture don't show the alpha channel)
For a QPaintDevice I use the widget itself, and I'm painting only with drawPixmap.
Now, the problem. As this widget is part of a huge collection of custom widgets there is a established workflow that I have to obey.
Firstly, I HAVE TO paint pixmap 1 - the basis. Then I have to paint pixmap2. However, for pixmap2 to receive the shadow effect from pixmap1 I have to use CompositionMode_DestinationOver. Unfortunately, this is not working. The result is:
(As you can see, the inner handle is not painted at all)
I suspect that the widget is taking a background image from it's parent for the transparent parts but I can't be sure. For that reason I've tried variety of Widget Attributes such as NoSystemBackground, TranslucentBackground, PaintOnScreen, etc, etc. Nothing worked. The inner handle is not painted when I use CompositionMode_DestinationOver.
To be sure that I didn't make a mistake with the pictures I've recreated the painting logic but instead of painting on a QWidget I was painting on QImage. Everything worked flawlessly with QImage!
So, for a test, I went on and tried putting QWidget::render (and save the resulting image on the HDD) at the end of the paintEvent, after everything is painted. The strangest thing is that if I don't use QWidget::DrawWindowBackground flag then the image on the HDD is the correct one (inner handle painted with the shadow effect dropping nicely on it), although what is on the desktop is not (not inner handle painted)!!!
I'm using Qt5.6 on Windows.
Not all paint devices (widgets, images, etc) support all composition modes.
QWidgetmight not, which is what I suppose is happening here.