def onMouseOver(self, event):
x = event.GetX()
y = event.GetY()
self.item, flags = self.listCtrl.HitTest((x, y))
if self.item < 0:
self.listCtrl.SetToolTipString("Colour codes Red - Loaded, Yellow - In Progress, Green - Finished, Blue - Invoiced, White - User defined")
return
if self.item != self.previous_item:
self.old_item = self.previous_item
self.previous_item = self.item
else:
return
bg_colour = self.listCtrl.GetItemBackgroundColour(self.item)
if bg_colour == wx.BLACK or bg_colour == wx.NullColour:
self.listCtrl.SetItemBackgroundColour(self.item,"#3246A8")
self.listCtrl.SetItemBackgroundColour(self.old_item,wx.BLACK)
elif bg_colour == "#3246A8":
self.listCtrl.SetItemBackgroundColour(self.item,wx.BLACK)
self.currentItem = self.item
rowid = self.listCtrl.GetItem(self.currentItem,13)
stat_test = rowid.GetText()
rowid = self.listCtrl.GetItem(self.currentItem,1)
file_test = rowid.GetText()
rowid = self.listCtrl.GetItem(self.currentItem,4)
running_test = rowid.GetText()
if stat_test == "0":
self.listCtrl.SetToolTipString("File currently playing\nRunning time "+running_test)
elif stat_test == "1":
self.listCtrl.SetToolTipString("In Progress\nRunning time "+running_test)
elif stat_test == "2":
self.listCtrl.SetToolTipString("Finished\nRunning time "+running_test)
elif stat_test == "3":
self.listCtrl.SetToolTipString("Invoiced\nRunning time "+running_test)
if file_test == self.file_playing and stat_test == "1":
self.listCtrl.SetToolTipString("File currently playing & In Progress\nRunning time "+running_test)
if file_test == self.file_playing and stat_test == "2":
self.listCtrl.SetToolTipString("File currently playing but Finished\nRunning time "+running_test)
if file_test == self.file_playing and stat_test == "3":
self.listCtrl.SetToolTipString("File currently playing but Invoiced\nRunning time "+running_test)
import wx
class MyListCtrl(wx.ListCtrl):
def __init__(self, parent, id):
wx.ListCtrl.__init__(self, parent, id)
self.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver)
self.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave)
def onMouseOver(self, event):
#Loop through all items and set bgcolor to default, then:
item = self.HitTest(event.GetPosition())
self.SetItemBackgroundColour(item, 'Green')
self.RefreshItems()
event.Skip()
def onMouseLeave(self, event):
#Loop through all items and set bgcolor to default, then:
self.RefreshItems()
event.Skip()
我会尝试在创建ListCtrl时获取其中一个ListItems的背景色并将其放入变量中:
然后用它来改变颜色。调用项的setter之后,有时还需要调用listcrl的SetItem(listItem)方法。由于某些原因,将背景设置为NullColour对ListCtrl不起作用。当我为我的一个应用程序创建一个暗模式时,我发现了这一点。我在这里写过:http://www.blog.pythonlibrary.org/2011/11/05/wxpython-creating-a-dark-mode/
我知道这是一个迟来的答复,但我使用以下方法: self.listCtrl.Bind(wx.EVT_运动, self.onMouseOver公司) 和设置自我上一项最初为-1
我用它来突出显示鼠标放在它上面的行,同时改变工具提示。在
我希望它能帮助别人
这并不是“容易”就可以实现的,但是您应该能够通过一些修补来完成它。在
您必须将mouseover和mouseout事件侦听器添加到wxListCtrl对象中,然后在每次获取mouseover事件时测试所命中的项。您可能可以缓存列表项的坐标,但如果您按此方法滚动列表和调整窗口大小可能会带来问题。在
一些让你开始的代码(没有经过测试,可能行不通,你需要在合适的wx.框架)公司名称:
相关问题 更多 >
编程相关推荐