[wxPython-users] Change the image of a list item (listctrl)
Robin Dunn
robin at alldunn.com
Sun Dec 3 16:28:28 PST 2006
Donn Ingle wrote:
> Hello, me again.
> I am going blue in the face trying to change the icon of an item in a list
> control.
>
> I have an Image list with two icons in it. It's assigned correctly.
> The icons are all set in a loop like so:
> for p in pl :
> ipog = Pog ( p )
> try: #catch pogs that are not properly formed
> if ipog.isInstalled ( ): i = 1
> else: i = 0
> li = wx.ListItem ( )
> li.SetImage ( i )
> li.SetText ( p )
> self.InsertItem ( li )
> Nevermind the fluff, the SetImage ( ) part works fine.
>
> So, later, when I select an item and click a button, I want that item's icon
> to change.
> I am here at the moment, no change actually happens:
> ii = self.GetFocusedItem ( )
> i = self.GetItem ( ii )
> print "PRE:", i.GetImage ( )
> i.SetImage ( 1 )
> print "POST:", i.GetImage ( )
Add a call to self.SetItem(i). When you call GetItem it gives you a
copy of the wx.ListItem object not a reference to something used
internally by the listctrl (because it is generated on the fly from the
native list item info) so you need to call SetItem to get that new image
info pushed back to the native widget.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list