473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

wxpython listctrl

8
Hello,

I was wondering if anyone knows how to change the color of a selected item in a listctrl (for example, on my system a selected item is highlighted in blue). I could not find any information on this, other than it is a system defined parameter. Any help is greatly appreciated.

Thanks in advance,
Stephen
Apr 3 '07 #1
8 11352
bartonc
6,596 Expert 4TB
Hello,

I was wondering if anyone knows how to change the color of a selected item in a listctrl (for example, on my system a selected item is highlighted in blue). I could not find any information on this, other than it is a system defined parameter. Any help is greatly appreciated.

Thanks in advance,
Stephen
In your EVT_LIST_ITEM_RIGHT_CLICK handler:
Expand|Select|Wrap|Line Numbers
  1. item = event.GetItem()
  2. SetItemBackgroundColour(item, colorTuple)
Apr 3 '07 #2
bartonc
6,596 Expert 4TB
In your EVT_LIST_ITEM_RIGHT_CLICK handler:
Expand|Select|Wrap|Line Numbers
  1. item = event.GetItem()
  2. SetItemBackgroundColour(item, colorTuple)
Of course, you'll probably want to keep the old value returned by
Expand|Select|Wrap|Line Numbers
  1. GetItemBackgroundColour()
around and set it back when you get an EVT_LIST_ITEM_DESELECTED event.
Apr 3 '07 #3
shuf
8
In your EVT_LIST_ITEM_RIGHT_CLICK handler:
Expand|Select|Wrap|Line Numbers
  1. item = event.GetItem()
  2. SetItemBackgroundColour(item, colorTuple)
I wanted to do the above on the EVT_LIST_ITEM_SELECTED event, so I assume that it will not be different. I bound the event to the following method:
Expand|Select|Wrap|Line Numbers
  1. def OnSelected(self, event):
  2.     item = event.GetItem()
  3.     self.listctrl.SetItemBackgroundColour(item, wx.RED)
  4.  
But, I get an error that a number is expected for argument number 2 (item). So if I change the code to:
Expand|Select|Wrap|Line Numbers
  1. def OnSelected(self, event):
  2.     item = self.listctrl.GetFirstSelected()
  3.     self.listctrl.SetItemBackgroundColour(item, wx.RED)
  4.  
It changes the color under the selection highlighting (I can only see the color if I deselect the item). Is there a way to change the selection highlighting color? Thanks again for your response.
Apr 3 '07 #4
bartonc
6,596 Expert 4TB
I wanted to do the above on the EVT_LIST_ITEM_SELECTED event, so I assume that it will not be different. I bound the event to the following method:

def OnSelected(self, event):
item = event.GetItem()
self.listctrl.SetItemBackgroundColour(item, wx.RED)

But, I get an error that a number is expected for argument number 2 (item). So if I change the code to:

def OnSelected(self, event):
item = self.listctrl.GetFirstSelected()
self.listctrl.SetItemBackgroundColour(item, wx.RED)

It changes the color under the selection highlighting (I can only see the color if I deselect the item). Is there a way to change the selection highlighting color? Thanks again for your response.
Yeah, I don't see anything about setting the selected color to a different color from the default either.
Apr 3 '07 #5
shuf
8
Yeah, I don't see anything about setting the selected color to a different color from the default either.
Thanks for your help.
Apr 3 '07 #6
bartonc
6,596 Expert 4TB
Thanks for your help.
a wx.Grid has what you are looking for:
Expand|Select|Wrap|Line Numbers
  1.         self.grid1.SetSelectionBackground(wx.Colour(115, 247, 121))
Apr 9 '07 #7
I'm fully aware this is in old thread, but I cam across exactly the same problem and this was the only directly relevent page that came up so I thought i'd post the solution here for anyone else that has the same issue in future.

You need to bind an event handler on EVT_LIST_ITEM_SELECTED then change the item's state flags in the handler like so:

Expand|Select|Wrap|Line Numbers
  1. ls = wx.ListCtrl
  2. ls.Bind(wx.EVT_LIST_ITEM_SELECTED, _item_selected)
  3.  
  4. def _item_selected(evt):
  5.     i = evt.GetIndex() # Find item selected
  6.     ls.SetItemState(i, wx.LIST_STATE_FOCUSED, wx.LIST_STATE_SELECTED) # Clear selected flag and just leave focused flag so that a box is drawn round selected item
  7.     evt.Skip() # Let the event propogate
  8.  
Nov 5 '07 #8
bartonc
6,596 Expert 4TB
I'm fully aware this is in old thread, but I cam across exactly the same problem and this was the only directly relevent page that came up so I thought i'd post the solution here for anyone else that has the same issue in future.

You need to bind an event handler on EVT_LIST_ITEM_SELECTED then change the item's state flags in the handler like so:

Expand|Select|Wrap|Line Numbers
  1. ls = wx.ListCtrl
  2. ls.Bind(wx.EVT_LIST_ITEM_SELECTED, _item_selected)
  3.  
  4. def _item_selected(evt):
  5.     i = evt.GetIndex() # Find item selected
  6.     ls.SetItemState(i, wx.LIST_STATE_FOCUSED, wx.LIST_STATE_SELECTED) # Clear selected flag and just leave focused flag so that a box is drawn round selected item
  7.     evt.Skip() # Let the event propogate
  8.  
Thank you very much. It's always appreciated when we get this kind of contribution.
Nov 5 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John Taylor | last post by:
I have a ListCtrl with 5 columns. The first 4 columns are either strings or integers, but the last column is a string in the format of MM-DD-YYYY. I searched google and also read over the...
1
by: Fabio Pliger | last post by:
Hi all, i'm working on a very large project using wx 2.5... On one frame i have a wx.lib.mixins.listctrl widget, wich is a listctrl extended with the possibility to edit the columns text...
0
by: Sven Tissot | last post by:
Hello, I am trying to build an editable ListCtrl_edit via TextEditMixin. It displays o.k. and I can edit the first field with this is the code piece: class VokabelListCtrl(wxListCtrl,...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this...
0
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this...
6
by: zdp | last post by:
Dear all: I made a window program by wxPython. Split windows, treectrl, listctrl and textctrl are used. When I program in python, the look & feel of the window controls are like the windos XP...
5
by: Benjamin | last post by:
I'm writing a search engine in Python with wxPython as the GUI. I have the actual searching preformed on a different thread from Gui thread. It sends it's results through a Queue to the results...
1
by: Benjamin | last post by:
Hello! I am writing a search engine with wxPython as the GUI. As the search thread returns items, it adds them to a Queue which is picked up by the main GUI thread calling itself recursively with...
1
by: vedrandekovic | last post by:
Hello, How can I Insert image with string in ListCtrl with this example: # Import ftputil module - like ftplib from ftputil import FTPHost # Create connection...
0
by: asrekdal | last post by:
Hi, I am working with a wxPython ListCtrl Control and wondering if it is possilbe to place images in the cell rather than a string? -- Andrew
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.