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.
User avatar
doublemax
Moderator
Moderator
Posts: 15860
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How make wxPanel transparent on Windows and Linux?

Post by doublemax » Thu Aug 21, 2014 11:13 am

So there is no way to get the semi-transparent on Windows? whether it is wxPanle or wxWindow?
It's possible. But either you need to create a bitmap with fixed transparency in PhotoShop or similar. Or you have to manipulate the alpha-values of the bitmap directly before drawing it.
Use the source, Luke!

Manolo
Can't get richer than this
Can't get richer than this
Posts: 726
Joined: Mon Apr 30, 2012 11:07 pm

Re: How make wxPanel transparent on Windows and Linux?

Post by Manolo » Thu Aug 21, 2014 3:02 pm

Does this helps?
wxWindow::SetTransparent(wxByte alpha)
http://docs.wxwidgets.org/trunk/classwx ... 0f45a0656f

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 » Fri Aug 22, 2014 2:03 am

Manolo wrote:Does this helps?
wxWindow::SetTransparent(wxByte alpha)
http://docs.wxwidgets.org/trunk/classwx ... 0f45a0656f
I'm afraid it doesn't work on Windows, and other platform I didn't try...cause I tried CanSetTransparent(), but it returns false...

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 » Fri Aug 22, 2014 2:07 am

And I also tried SetBackgroundColor(wxColour(r,g,b,a))...It also doesn't work.

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 » Fri Aug 22, 2014 7:09 am

doublemax wrote:
So there is no way to get the semi-transparent on Windows? whether it is wxPanle or wxWindow?
It's possible. But either you need to create a bitmap with fixed transparency in PhotoShop or similar. Or you have to manipulate the alpha-values of the bitmap directly before drawing it.
I tried, but just draw the bitmap with alpha channel as background still doesn't work. (I use wxPaintDC, DrawBitmap in the wxPanel's paintEvent...and I the bitmap's HasAlpha() returns true..)
Then, I tried to make the wxPanel transparent...(1)use the default the wxPanel(); (2)SetBackgroundStyle(wxBG_STYLE_TRANSPARENT); (3)wxPanel::Create(pParent,...) in the ctor. And I got the "semi-transparent" bitmap background......BUT, there is a problem, As my situation is a Big panel on the wxScrollWindow, and some small panel on the Big panel & they are the child of the Big panel....SO the wired problem is the small panel is totoally transparent to the wxScrolllWindow's background, withou show the Big panel ! And I really don't know how to solve this problem...

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 » Fri Aug 22, 2014 7:12 am

doublemax wrote:Or you have to manipulate the alpha-values of the bitmap directly before drawing it.
Or this way is easier and more available? But what API should I use to do this? wxGraphicsContext::BeginLayer (which u said yesterday that it doesn't work on Windows)? or some other ways to do it ?

gpu
Experienced Solver
Experienced Solver
Posts: 92
Joined: Tue Aug 12, 2014 3:46 am

aaaaaa

Post by gpu » Fri Aug 22, 2014 7:24 am

aaaaaa
Last edited by gpu on Fri Aug 22, 2014 8:47 am, edited 1 time in total.

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 » Fri Aug 22, 2014 7:56 am

I solved there problem use SetWindowStyle(wxTRANSPARENT_WINDOW) for both the Big and Small panel. And what about another platform, can I directly use SetBackgroundStyle(wxBG_STYLE_TRANSPARENT) on MAC/LINUX instead ?
Then the problem left is how to make the various controls background "transparent"...I found a topic and just read it. http://forums.wxwidgets.org/viewtopic.php?f=1&t=38262 And can the wxStaticText get dealed with the same idea in that topic? I'am tring...by the way, is there any API such as SetWindowStyle and SetBackgroundStyle for various controls including button, statictext, combo, list, etc. I tried them for button, and they didn't work as SetWindowStyle works for panel on Windows.

User avatar
doublemax
Moderator
Moderator
Posts: 15860
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How make wxPanel transparent on Windows and Linux?

Post by doublemax » Fri Aug 22, 2014 10:11 am

And what about another platform, can I directly use SetBackgroundStyle(wxBG_STYLE_TRANSPARENT) on MAC/LINUX instead ?
I only work under Windows and don't know about other platforms, you may have to try it out.
by the way, is there any API such as SetWindowStyle and SetBackgroundStyle for various controls including button, statictext, combo, list, etc. I tried them for button, and they didn't work as SetWindowStyle works for panel on Windows.
Displaying native controls semi-transparently over custom background is practically impossible.
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 » Sat Aug 23, 2014 2:31 am

doublemax wrote:
Displaying native controls semi-transparently over custom background is practically impossible.
not semi-transparent...I saw it override the SetTransparent kinda of API from wxWindow...but it doesn't work like wxPanel

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 » Tue Aug 26, 2014 10:55 am

I use wxScrollWindow<wxPanel> as the main frame, and it's not transparent or semi-transparent...
the small myPanel I use the bitmap way to make it semi-transparent, but
(1) eg, if i use dc draw sth on the wxScollWindow, expect the 1st I constuct on the thing I drawn on wxScrollWindow it it seems semi-transparent, other situaions if I drag it to another position and refresh() it seems not semi-transparent.
(2) myPanel(include various controls) are just construct as the wxScrollWindow's children, and i just drawn it's background bitmap, which I mean I didn't control the controls' drawing......So if I use wxScrollWindow dc draw sth, they are always on the bottom of the myPanel(and the controls on it)...is there any way to draw the things at the top of them?

User avatar
doublemax
Moderator
Moderator
Posts: 15860
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How make wxPanel transparent on Windows and Linux?

Post by doublemax » Tue Aug 26, 2014 9:41 pm

I have difficulties understanding what exactly you're asking, so i'll answer more generally:

The wxScrolledWindow is the background of everything, so AFAIU it will not be transparent. The panels on top should be semi-transparent so that the background ( the wxScrolledWindow ) shines through.

When you're drawing the panel using the method i suggested earlier, you're actually just faking the transparency. Because first you're drawing the background from the parent ( the wxScrolledWindow ) without transparency, then you draw the other content of the panel with 50% (or whatever) transparency.
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 » Wed Aug 27, 2014 2:23 am

doublemax wrote:I have difficulties understanding what exactly you're asking, so i'll answer more generally:

The wxScrolledWindow is the background of everything, so AFAIU it will not be transparent. The panels on top should be semi-transparent so that the background ( the wxScrolledWindow ) shines through.

When you're drawing the panel using the method i suggested earlier, you're actually just faking the transparency. Because first you're drawing the background from the parent ( the wxScrolledWindow ) without transparency, then you draw the other content of the panel with 50% (or whatever) transparency.
Yes I know, my problem is when i create the myPanle, it's semi-transparent...but once I move the myPanel(I called Refresh), it seems still semi-transparent, but when I drawed a circle on the wxScrollWindow use paintEve and dc, after I move the myPanel, the circle I can''t see through the semi-transparent myPanel(meanwhile, I think it's still semi-tranparent, but through it I can just see the wxScrollWindow color which I set by SetBackgroundColour)

User avatar
doublemax
Moderator
Moderator
Posts: 15860
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How make wxPanel transparent on Windows and Linux?

Post by doublemax » Wed Aug 27, 2014 6:35 am

but when I drawed a circle on the wxScrollWindow use paintEve and dc, after I move the myPanel, the circle I can''t see through the semi-transparent myPanel
In that case, if the parent window contains more than just a background bitmap, you need a way to tell the parent window to render into another wxDC.

Something like this:

Code: Select all

MyScrolledWindow::Render( wxDC &dc, const wxRect &rect )
{
   // this code needs to draw the content of the given rect into that wxDC
}

MyChildPanel::OnPaint( wxPaintEvent &event )
{ 
   wxBufferedPaintDC dc(this);

   MyScrolledWindow *parent = wxDynamicCast( GetParent(), MyScrolledWindow );
   if( parent!=NULL )
   {
       parent->Render( dc, GetRect() );
       // now draw the content of your panel of top of the background
   }
}
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 » Wed Aug 27, 2014 8:30 am

I tried like this:

Code: Select all

Parent::paintEvent(wxPaintEvent&)
{
wxPaintDC(this);  //
Render(dc, GetRect());
}
Parent::Render(wxDC& dc, const wxRect&)
{
dc.setPen();
//draw sth
dc.SetPen(wxNullPen);
}
//////////////////////////////////////
Child::paintEvent(wxPaintEvent&)
{
wxBufferedPaintDC(this);  //
Render(dc, GetRect());
}
Child::Render(wxDC& dc, const wxRect&)
{
//..getParent
parent->Render(dc, GetRect());
dc.DrawBitmap;  //the semi-transparent background
}
the result now is that the Child's background not semi-transparent, and the back groundcolor is black, the bitmap is on the black.
is the DC wrong somewhere ?

Post Reply