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
8 11352
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: -
item = event.GetItem()
-
SetItemBackgroundColour(item, colorTuple)
In your EVT_LIST_ITEM_RIGHT_CLICK handler: -
item = event.GetItem()
-
SetItemBackgroundColour(item, colorTuple)
Of course, you'll probably want to keep the old value returned by - GetItemBackgroundColour()
around and set it back when you get an EVT_LIST_ITEM_DESELECTED event.
In your EVT_LIST_ITEM_RIGHT_CLICK handler: -
item = event.GetItem()
-
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: -
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.
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.
Yeah, I don't see anything about setting the selected color to a different color from the default either.
Thanks for your help.
Thanks for your help.
a wx.Grid has what you are looking for: -
self.grid1.SetSelectionBackground(wx.Colour(115, 247, 121))
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: -
ls = wx.ListCtrl
-
ls.Bind(wx.EVT_LIST_ITEM_SELECTED, _item_selected)
-
-
def _item_selected(evt):
-
i = evt.GetIndex() # Find item selected
-
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
-
evt.Skip() # Let the event propogate
-
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: -
ls = wx.ListCtrl
-
ls.Bind(wx.EVT_LIST_ITEM_SELECTED, _item_selected)
-
-
def _item_selected(evt):
-
i = evt.GetIndex() # Find item selected
-
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
-
evt.Skip() # Let the event propogate
-
Thank you very much. It's always appreciated when we get this kind of contribution.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |