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 11358 bartonc 6,596
Recognized Expert Expert
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_R IGHT_CLICK handler: -
item = event.GetItem()
-
SetItemBackgroundColour(item, colorTuple)
bartonc 6,596
Recognized Expert Expert
In your EVT_LIST_ITEM_R IGHT_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_D ESELECTED event.
In your EVT_LIST_ITEM_R IGHT_CLICK handler: -
item = event.GetItem()
-
SetItemBackgroundColour(item, colorTuple)
I wanted to do the above on the EVT_LIST_ITEM_S ELECTED 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.
bartonc 6,596
Recognized Expert Expert
I wanted to do the above on the EVT_LIST_ITEM_S ELECTED 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.S etItemBackgroun dColour(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.G etFirstSelected ()
self.listctrl.S etItemBackgroun dColour(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.
bartonc 6,596
Recognized Expert Expert
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_S ELECTED 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
-
bartonc 6,596
Recognized Expert Expert
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_S ELECTED 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
ColumnSorterMixin code & examples, but still can not figure out how to
to write a user-defined sort routine just for the last column in order
to sort that...
|
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 entrys.... Anyone know if it's possible
(or if there's a widget...) to have also the possbility to have a comboBox
in the list (with the text edit entry)?...
|
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,
listmix.ListCtrlAutoWidthMixin,
listmix.TextEditMixin):
def __init__(self, parent, ID, pos=wxDefaultPosition,
|
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 version, many of which are listed
below and at http://wxpython.org/recentchanges.php.
What is wxPython?
|
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 version, many of which are listed
below and at http://wxpython.org/recentchanges.php.
What is wxPython?
| |
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 look & feel, with thin and flat
border (My os is window XP). It's natural because, as I know, wxPython
use native look and feel.
But when I...
|
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 ListCtrl which
adds a new item. This works fine or small searches, but when the
results number in the hundreds, the GUI is frozen for the duration of...
|
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
wx.CallAfter. These are then added to a ListCtrl. This works fine for
small searches, but with larger and longer searchs the GUI is clogged
and...
|
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
ftp=FTPHost("ftp.someserver.com","user","password")
# LIST ALL FILES/FOLDERS ON SERVER
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |