I am trying to use icons in a ListCtrl report view with Windows.
I have managed to display the icons in whichever column I like (thanks to several posts from Robin which discuss the issue with Windows displaying always the icons in the first column).
However, I cannot get the icons to display with transparency, the background is always white.
Is this another bug in Windows ?
Are there any suggestions for a work-around?
The option I have is to put the icon in the first column so it doesnt break the row colour in the middle…
This is what I want versus what I get today in Windows…
I tried also with a PNG I created (which displays with a transparent background in an image viewer)
Here is my example code:
import wx
class MyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, wx.ID_ANY, "ListCtrl Icon Example", size=(300, 200))
self.panel = wx.Panel(self)
il_icons = wx.ImageList(16, 16, initialCount=5)
il_icons.Add(wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_MENU, (1, 1)))
il_icons.Add(wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_MENU, (16, 16)))
il_icons.Add(wx.ArtProvider.GetBitmap(wx.ART_ERROR, wx.ART_MENU, (16, 16)))
il_icons.Add(wx.ArtProvider.GetBitmap(wx.ART_WARNING, wx.ART_MENU, (16, 16)))
tmp_bmp = wx.Bitmap(r"Warning.png", wx.BITMAP_TYPE_PNG)
tmp_bmp.SetMaskColour(wx.Colour(255,255,255))
il_icons.Add(tmp_bmp)
lc_list = wx.ListCtrl(self.panel, wx.ID_ANY, style=wx.LC_REPORT | wx.LC_SINGLE_SEL | wx.LC_EDIT_LABELS | wx.LC_VRULES, name='lc_list')
lc_list.AssignImageList(il_icons, which=wx.IMAGE_LIST_SMALL)
lc_list.InsertColumn(0, 'image', format=wx.LIST_FORMAT_LEFT, width=0)
lc_list.InsertColumn(1, 'col01', format=wx.LIST_FORMAT_LEFT, width=64)
lc_list.InsertColumn(2, 'col02', format=wx.LIST_FORMAT_RIGHT, width=64)
lc_list.InsertItem(0,"", -1)
lc_list.SetItem(0, 1, 'item01')
lc_list.SetItem(0, 2, '100', 2)
lc_list.InsertItem(1,"", -1)
lc_list.SetItem(1, 1, 'item02')
lc_list.SetItem(1, 2, '200', 3)
lc_list.SetItemBackgroundColour(1, "green")
lc_list.InsertItem(2,"", -1)
lc_list.SetItem(2, 1, 'item01')
lc_list.SetItem(2, 2, '300', 5)
lc_list.SetItemBackgroundColour(2, "yellow")
lc_list.InsertItem(3, "", -1)
lc_list.SetItem(3, 1, 'item06')
lc_list.SetItem(3, 2, '300', 4)
lc_list.SetItemBackgroundColour(3, "red")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(lc_list, 1, wx.EXPAND | wx.ALL)
self.panel.SetSizer(sizer)
if __name__ == '__main__':
app = wx.App()
frame = MyFrame(None)
frame.Show(True)
app.MainLoop()