How to draw transparency in a custom widget?

I have a custom widget that has a drop shadow, the problem I'm having is as I'm
not drawing a background before each paint event the semi-transparent shadow
quickly stacks up and turns black. I'm not sure how to repaint the background
between paints as this could be anything because the shadow should draw over what
ever is behind (could be a panel of any colour, another widget etc.)

How can I draw a "transparent" background and reset the drawing on each paint
event so I can keep the shadows?

There really isn't a good way to do that from wx. Usually the OS takes care of things like shadows around windows, so you could probably fake it by using a frame with no decorations as your popup, but that will have some limitations and maybe some problems. The other option is to use a wx.ScreenDC to capture the portion of the screen beneath your popup and then draw that bitmap first and the content of your widget on top of that, so it appears that your popup is transparent. Unfortunately that will work on some platforms but may have issues on others.

···

On 1/17/12 11:56 AM, Paul wrote:

I have a custom widget that has a drop shadow, the problem I'm having is as I'm
not drawing a background before each paint event the semi-transparent shadow
quickly stacks up and turns black. I'm not sure how to repaint the background
between paints as this could be anything because the shadow should draw over what
ever is behind (could be a panel of any colour, another widget etc.)

How can I draw a "transparent" background and reset the drawing on each paint
event so I can keep the shadows?

--
Robin Dunn
Software Craftsman

There really isn't a good way to do that from wx. Usually the OS takes
care of things like shadows around windows, so you could probably fake
it by using a frame with no decorations as your popup, but that will
have some limitations and maybe some problems. The other option is to
use a wx.ScreenDC to capture the portion of the screen beneath your
popup and then draw that bitmap first and the content of your widget on
top of that, so it appears that your popup is transparent.
Unfortunately that will work on some platforms but may have issues on
others.

Ah, Thanks Robin.

I'd need something that will work over all platforms so maybe it's not worth it
to have a shadow :slight_smile: I'll look into ScreenDC though and see what I can do

Paul