473,545 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxpython listctrl

8 New Member
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 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:
Expand|Select|Wrap|Line Numbers
  1. item = event.GetItem()
  2. SetItemBackgroundColour(item, colorTuple)
Apr 3 '07 #2
bartonc
6,596 Recognized Expert Expert
In your EVT_LIST_ITEM_R IGHT_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_D ESELECTED event.
Apr 3 '07 #3
shuf
8 New Member
In your EVT_LIST_ITEM_R IGHT_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_S ELECTED 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 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.
Apr 3 '07 #5
shuf
8 New Member
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 Recognized Expert Expert
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
CraigDouglas
1 New Member
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:

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 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:

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
4292
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...
1
2527
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)?...
0
1671
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,
0
1649
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?
0
1527
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?
6
4753
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...
5
2602
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...
1
1726
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...
1
3584
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
0
1239
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
7475
marktang
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...
0
7409
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...
0
7664
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, 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. ...
0
7918
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7436
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...
0
7766
tracyyun
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...
0
5981
agi2029
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...
1
5341
isladogs
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...
1
1022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.