How make wxPanel transparent on Windows and Linux?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

How make wxPanel transparent on Windows and Linux?

Post by gpu »

How make wxPanel transparent on Windows and Linux?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How make wxPanel transparent on Windows and Linux?

Post by doublemax »

Dealing with transparency is always a difficult issue in wxWidgets. What exactly are you trying to achieve?
Use the source, Luke!
gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: How make wxPanel transparent on Windows and Linux?

Post by gpu »

doublemax wrote:Dealing with transparency is always a difficult issue in wxWidgets. What exactly are you trying to achieve?
i want the panel be transparent, and i tried CanGetTransparent, but unfortunately it returns false on Windows.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How make wxPanel transparent on Windows and Linux?

Post by doublemax »

Semi-transparency is not possible. A completely transparent panel would be pretty much useless, it'd be just a layout element, then you could use a wxSizer instead.

You can also try wxWindow::SetBackgroundStyle( wxBG_STYLE_TRANSPARENT )
http://docs.wxwidgets.org/trunk/classwx ... f9fd6594ec
Use the source, Luke!
gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: How make wxPanel transparent on Windows and Linux?

Post by gpu »

doublemax wrote:Semi-transparency is not possible. A completely transparent panel would be pretty much useless, it'd be just a layout element, then you could use a wxSizer instead.

You can also try wxWindow::SetBackgroundStyle( wxBG_STYLE_TRANSPARENT )
http://docs.wxwidgets.org/trunk/classwx ... f9fd6594ec
Thank you very much.
But what I want is Semi-transparency...is it REALLY no way to make it Semi-transparency? THX
gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: How make wxPanel transparent on Windows and Linux?

Post by gpu »

is it possible to use a semi-transparent Bitmap as the background?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How make wxPanel transparent on Windows and Linux?

Post by doublemax »

What's never possible is to have a native control, e.g. a button, to be semi-transparent over a custom background.

If you draw content yourself, everything is possible, but not always easy.

It would really help if you had a screenshot or something else that shows what exactly you're trying to do.
Use the source, Luke!
gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: How make wxPanel transparent on Windows and Linux?

Post by gpu »

doublemax wrote:What's never possible is to have a native control, e.g. a button, to be semi-transparent over a custom background.

If you draw content yourself, everything is possible, but not always easy.

It would really help if you had a screenshot or something else that shows what exactly you're trying to do.
Thank you, and here is the link for what i want. The widget(panel here) should be semi-tranparent.
http://forums.wxwidgets.org/viewtopic.php?f=27&t=39907
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How make wxPanel transparent on Windows and Linux?

Post by doublemax »

Ok, now i see the "bigger picture". Together with your question about zooming, you'll definitely need a 100% custom control. The main question is whether the individual panels are wxWidgets controls, too or if everything is managed by yourself. The latter case is guaranteed to work as it gives you total freedom, but of course it's more work.

If the panels are wxWidgets controls, e.g. a wxPanel, the easiest way to get transparency would be to access the background bitmap directly. In the paint event handler you draw the correct portion of the background bitmap first, then you can draw the other content on top, if you want semi-transparent.
Use the source, Luke!
gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: How make wxPanel transparent on Windows and Linux?

Post by gpu »

doublemax wrote:Ok, now i see the "bigger picture". Together with your question about zooming, you'll definitely need a 100% custom control. The main question is whether the individual panels are wxWidgets controls, too or if everything is managed by yourself. The latter case is guaranteed to work as it gives you total freedom, but of course it's more work.

If the panels are wxWidgets controls, e.g. a wxPanel, the easiest way to get transparency would be to access the background bitmap directly. In the paint event handler you draw the correct portion of the background bitmap first, then you can draw the other content on top, if you want semi-transparent.
Thank you very much! I will try
gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: How make wxPanel transparent on Windows and Linux?

Post by gpu »

doublemax wrote:Ok, now i see the "bigger picture". Together with your question about zooming, you'll definitely need a 100% custom control. The main question is whether the individual panels are wxWidgets controls, too or if everything is managed by yourself. The latter case is guaranteed to work as it gives you total freedom, but of course it's more work.

If the panels are wxWidgets controls, e.g. a wxPanel, the easiest way to get transparency would be to access the background bitmap directly. In the paint event handler you draw the correct portion of the background bitmap first, then you can draw the other content on top, if you want semi-transparent.
Help:) I didn't find how to access the bitmap, there is only a GetBackgroundBitmap for wxWindow...And I just find a way to draw bitmap by wxPaintDC.
Thank you .
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How make wxPanel transparent on Windows and Linux?

Post by doublemax »

Sorry, i wasn't clear enough. There is no wxWindow method for this. This was assuming that you have a wxBitmap somewhere that you're using to draw the background. How you access that bitmap is up to you.
Use the source, Luke!
gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: How make wxPanel transparent on Windows and Linux?

Post by gpu »

doublemax wrote:Sorry, i wasn't clear enough. There is no wxWindow method for this. This was assuming that you have a wxBitmap somewhere that you're using to draw the background. How you access that bitmap is up to you.
I'am alittle puzzled:) I mean that there is no default API to get/set bitmap for wxPanel, but the wxWindow do have (eg. GetBackgroundBitmap).
So ur decision is that I use wxPaintDC to draw the bitmap as the background of the wxPanel.....But I still don't how make the wxPanel's backgound semi-trasparent? Use a semi-transparent bitmap?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How make wxPanel transparent on Windows and Linux?

Post by doublemax »

There are methods like SetBackground(...) and GetBackgroundBitmap(...), but they're not officially documented and AFAICS they're only used in wxUniversal.

There is wxCustomBackgroundWindow though, but i remember a post from someone else saying that it doesn't work correctly with a wxScrolledWindow and i assume that's the window type that you're going to use for the background.
http://docs.wxwidgets.org/trunk/classwx ... indow.html
But I still don't how make the wxPanel's backgound semi-trasparent? Use a semi-transparent bitmap?
Yes. Unfortunately there is no simple call with which you can set the transparency value of the bitmap. Theoretically you could use wxGraphicsContext::BeginLayer(...) for it, but unfortunately it's not implemented under MSW.
Use the source, Luke!
gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

Re: How make wxPanel transparent on Windows and Linux?

Post by gpu »

doublemax wrote:There are methods like SetBackground(...) and GetBackgroundBitmap(...), but they're not officially documented and AFAICS they're only used in wxUniversal.

There is wxCustomBackgroundWindow though, but i remember a post from someone else saying that it doesn't work correctly with a wxScrolledWindow and i assume that's the window type that you're going to use for the background.
http://docs.wxwidgets.org/trunk/classwx ... indow.html
But I still don't how make the wxPanel's backgound semi-trasparent? Use a semi-transparent bitmap?
Yes. Unfortunately there is no simple call with which you can set the transparency value of the bitmap. Theoretically you could use wxGraphicsContext::BeginLayer(...) for it, but unfortunately it's not implemented under MSW.
So there is no way to get the semi-transparent on Windows? whether it is wxPanle or wxWindow?
Post Reply