PDA

View Full Version : Paintevent and transparent children



wishper
10th August 2010, 15:38
Hi guys !
I'm facing a problem right now, and I don't find any solution, or ever subject who can help me to resolve it. If you know Flash, or AfterEffect, I try to do a Timeline like the one you can found in theses software.

First of all, all my classes inherits QWidget.
Now I have a class I use to make the background : Line. To do that, I use the paintEvent method to draw the background, and the borders.
Next, I have a class, that I call Key (to make it simple, a QPixmap in a QLabel). The fact is that a Line contains some Keys, placed in function of a value. So all Keys are children of a Line.

The problem came when the keys have some transparent part in them. Like you can see in the image in attachment, my Key pixmap is a transparent square with a black circle in the middle. And in the transparent part, where I should have the white of the Line behind him, I see the classic background that all my widgets have.

What I understand is that the paintEvent don't draw behind the widget children, is there any way to force it ?

I looked in the flags, but don't find my pleasure.

I am open to any suggestion, thanks a lot for any help you can provide !

axeljaeger
16th August 2010, 16:40
See widget attribute Qt::WA_TranslucentBackground

wishper
18th August 2010, 14:17
Well, I tried this, and it doesn't works. The problem came from the fact that the widget doesn't know which region is transparent, and don't redraw under transparent pixels.
But, just know, I thought about one thinks, and the documentation gave me the answer. You can define a mask over your widget, for case like this.
The solution was really simple with this :
myWidget.setPixmap(pixmap)
myWidget.setMask(pixmap.mask())