Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wxPython wxListCtrl selected row color

I want to have certain rows selected color be red instead of the standard color (blue on windows) so that I can indicate status. Anyone know if this is possible in wxPython?

like image 873
flxkid Avatar asked Dec 18 '22 09:12

flxkid


1 Answers

In your class that you derive from wx.ListCtrl, take a look at overriding

def OnGetItemAttr(self, item):
    return self.normalAttr[item % 2]
#

Where the item attributes are initialized ahead of time using:

    self.normalAttr = []
    self.normalAttr.append(wx.ListItemAttr())
    grayAttr = wx.ListItemAttr()
    grayAttr.SetBackgroundColour(lightGray)
    self.normalAttr.append(grayAttr)

So in this case, I'm alternating background colors between the default, and a light Gray attribute.

This function is called for each row as its painted, so you can use it to indicate all sorts of status. If row is selected should be an easy case.

like image 195
Jim Carroll Avatar answered Jan 06 '23 20:01

Jim Carroll