wxStaticText with transparent backgroun ?? Topic is solved

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.
Post Reply
Lech Kozarski
Earned a small fee
Earned a small fee
Posts: 20
Joined: Sat Nov 26, 2011 3:15 pm

wxStaticText with transparent backgroun ??

Post by Lech Kozarski » Tue Sep 18, 2012 9:42 pm

Welcome. I am looking for help with the implementation of a transparent background on wxStaticTex (label)
When I select wxWindows_Transparen style, unfortunately, it does not change anything in the program.
I have some default background but i need TRANSPARENT BACKGROUND.
I use wxImagePanel (image as the main background of the program) , with label and wxListCtrl. ( All are on sizers )
( wxWidgest 2.9.4 last bulid )
Thanks in advance.

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

Re: wxStaticText with transparent backgroun ??

Post by Manolo » Tue Sep 18, 2012 11:18 pm

There is a still active work on this issue, partially solved:
http://trac.wxwidgets.org/ticket/14492

Lech Kozarski
Earned a small fee
Earned a small fee
Posts: 20
Joined: Sat Nov 26, 2011 3:15 pm

Re: wxStaticText with transparent backgroun ??

Post by Lech Kozarski » Thu Sep 20, 2012 10:21 pm

Thanks for help.
After this ( and compile wxWidgets again ) all works fine.

wxBen
Experienced Solver
Experienced Solver
Posts: 53
Joined: Wed Jun 06, 2012 4:44 pm
Location: Calgary, Canada

Re: wxStaticText with transparent background ??

Post by wxBen » Tue Oct 02, 2012 10:19 pm

Rather than one set of controversial changes (if you read the Trac item mentioned), a number of other smaller changes have been made that now allow you to more easily make transparent controls under MS Windows as shown below. However, please note that this currently only works on the latest SVN version of the code, as the code change to handle the wxTRANSPARENT_WINDOW is missing otherwise. If need a work around for older versions of the wxWidgets code base, then the changes shown in the Trac item will still work.

Code: Select all

wxStaticText* text = new wxStaticTextTransparent(parent, eventId, label, wxDefaultPosition, wxDefaultSize, wxTRANSPARENT_WINDOW);

wxCheckBox* checkBox = new wxCheckBoxTransparent(parent, eventId, label, wxDefaultPosition, wxDefaultSize, wxTRANSPARENT_WINDOW);

wxRadioButton* rButton = new wxRadioButtonTransparent(parent, eventId, label, wxDefaultPosition, wxDefaultSize, wxTRANSPARENT_WINDOW);

//------------------------------------------------------------------------------
class wxStaticTextTransparent : public wxStaticText
   {
   public:
      wxStaticTextTransparent(wxWindow *parent,
                    wxWindowID id,
                    const wxString& label,
                    const wxPoint& pos = wxDefaultPosition,
                    const wxSize& size = wxDefaultSize,
                    long style = 0,
                    const wxString& name = wxStaticTextNameStr)
         :wxStaticText(parent, id, label, pos, size, style, name)
         {
         }

       virtual WXHBRUSH MSWControlColor(WXHDC pDC, WXHWND hWnd)
          {
          wxColour fgColour = GetForegroundColour();
          ::SetTextColor((HDC)pDC, RGB(fgColour.Red(), fgColour.Green(), fgColour.Blue()));
          ::SetBkMode((HDC)pDC, TRANSPARENT);
          return (WXHBRUSH)GetStockObject(HOLLOW_BRUSH);
          }
   };

//------------------------------------------------------------------------------
class wxCheckBoxTransparent : public wxCheckBox
   {
   public:
      wxCheckBoxTransparent(wxWindow *parent,
                  wxWindowID id,
                  const wxString& label,
                  const wxPoint& pos = wxDefaultPosition,
                  const wxSize& size = wxDefaultSize,
                  long style = 0,
                  const wxValidator& validator = wxDefaultValidator,
                  const wxString& name = wxCheckBoxNameStr)
         :wxCheckBox(parent, id, label, pos, size, style, validator, name)
         {
         }

       virtual WXHBRUSH MSWControlColor(WXHDC pDC, WXHWND hWnd)
          {
          wxColour fgColour = GetForegroundColour();
          ::SetTextColor((HDC)pDC, RGB(fgColour.Red(), fgColour.Green(), fgColour.Blue()));
          ::SetBkMode((HDC)pDC, TRANSPARENT);
          return (WXHBRUSH)GetStockObject(HOLLOW_BRUSH);
          }
   };

//------------------------------------------------------------------------------
class wxRadioButtonTransparent : public wxRadioButton
   {
   public:
      wxRadioButtonTransparent(wxWindow *parent,
                  wxWindowID id,
                  const wxString& label,
                  const wxPoint& pos = wxDefaultPosition,
                  const wxSize& size = wxDefaultSize,
                  long style = 0,
                  const wxValidator& validator = wxDefaultValidator,
                  const wxString& name = wxRadioButtonNameStr)
         :wxRadioButton(parent, id, label, pos, size, style, validator, name)
         {
         }

       virtual WXHBRUSH MSWControlColor(WXHDC pDC, WXHWND hWnd)
          {
          wxColour fgColour = GetForegroundColour();
          ::SetTextColor((HDC)pDC, RGB(fgColour.Red(), fgColour.Green(), fgColour.Blue()));
          ::SetBkMode((HDC)pDC, TRANSPARENT);
          return (WXHBRUSH)GetStockObject(HOLLOW_BRUSH);
          }
   };

rakeshthp
I live to help wx-kind
I live to help wx-kind
Posts: 154
Joined: Mon Apr 06, 2009 10:02 am
Location: India

Re: wxStaticText with transparent backgroun ??

Post by rakeshthp » Tue Oct 09, 2012 7:06 am

Hi wxBen,

Has your patch been added in to the latest SVN or do we need to derive our own classes as shown in the code sample above?

Thanks

Victory
Experienced Solver
Experienced Solver
Posts: 97
Joined: Fri Mar 19, 2010 1:20 am

Re: wxStaticText with transparent backgroun ??

Post by Victory » Thu Jun 02, 2016 1:45 pm

Resurrecting this old thread...

What is the way to draw wxStaicText with transparent background?

Looking at the trac item referred to above, it sounds like the proposed solution ran into issues and hence possibly did not make itself into wxWidgets release??

Post Reply