Transparency of XPM and wxTaskBarIcon

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
Joelito
Earned some good credits
Earned some good credits
Posts: 128
Joined: Wed Jun 18, 2008 8:35 pm
Location: Tijuana, BC, México

Transparency of XPM and wxTaskBarIcon

Post by Joelito »

Code: Select all

#include "myicon.xpm"

MyTrayIcon::MyTrayIcon(MyAppFrame* parent,const wxString& tooltip)
    : me(parent)
{
    wxIcon icon(wxICON(myicon));
    SetIcon(icon,tooltip);
}
With above code, shows my icon in the taskbar without transparency, which it IS transparent...and the transparent part is white...

Any ideas...
* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux x86_64 with xfce desktop & wxgtk{2,3}-3.0.5.
O. S. J.
In need of some credit
In need of some credit
Posts: 6
Joined: Fri Nov 05, 2010 7:30 pm

Post by O. S. J. »

Create a wxMask from the Icon and apply this mask back to the icon.
Joelito
Earned some good credits
Earned some good credits
Posts: 128
Joined: Wed Jun 18, 2008 8:35 pm
Location: Tijuana, BC, México

Post by Joelito »

O. S. J. wrote:Create a wxMask from the Icon and apply this mask back to the icon.
Hi OSJ, I make a change in my code, now I'm using a png icon with "255,0,255" background:

Code: Select all

wxImage::AddHandler(new wxPNGHandler);
    wxIcon trayicon = wxIcon(icon_path,wxBITMAP_TYPE_PNG);
    wxBitmap TempBMP;
    TempBMP.CopyFromIcon(trayicon);
    wxMask* new_mask = new wxMask(TempBMP, wxColour(255,0,255));
    TempBMP.SetMask(new_mask);
    trayicon.CopyFromBitmap(TempBMP);
SetIcon(trayicon,tooltip);
It shows my icon but no transparency.
Here:
Image
* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux x86_64 with xfce desktop & wxgtk{2,3}-3.0.5.
bigpilot
I live to help wx-kind
I live to help wx-kind
Posts: 184
Joined: Tue Sep 19, 2006 8:33 am

Re: Transparency of XPM and wxTaskBarIcon

Post by bigpilot »

That should work. I'm using more or less the same code and it works:

Code: Select all

  wxBitmap icon( ProgIcon_xpm );
  wxMask* pMask = new wxMask( icon, wxColor( 0, 0, 0 ) );
  icon.SetMask( pMask );
  wxIcon program_icon;
  program_icon.CopyFromBitmap( icon );
  SetIcon( program_icon );
But note that your bitmap needs to be 16 x 16 pixels.
Soon to be world famous ;)
Post Reply