정보가있는 테이블 (행 및 열 필드 포함)을 표시하는 wxListCtrl이 있습니다. 일반적으로 행은 마우스 버튼으로 클릭 할 때만 강조 표시됩니다. 그러나 그것을 클릭하지 않고 하이라이트를하고 싶습니다. 즉 마우스를 다른 행으로 이동하면 마우스를 클릭하지 않고 행이 강조 표시됩니다. 이것이 가능한가?MouseOver의 wx.ListCtrl에서 ListItem 강조 표시
########################################################################
수입 WX
수입 SYS,이 없다 "쉽게"상자 밖으로 이루어집니다
class MyForm(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "List Control Tutorial")
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)
self.index = 0
self.list_ctrl = wx.ListCtrl(panel, size=(-1,100),
style=wx.LC_REPORT
|wx.BORDER_SUNKEN
)
self.list_ctrl.InsertColumn(0, 'Subject')
self.list_ctrl.InsertColumn(1, 'Due')
self.list_ctrl.InsertColumn(2, 'Location', width=125)
self.list_ctrl.Bind(wx.EVT_ENTER_WINDOW, self.onMouseOver)
self.list_ctrl.Bind(wx.EVT_LEAVE_WINDOW, self.onMouseLeave)
btn = wx.Button(panel, label="Add Line")
btn.Bind(wx.EVT_BUTTON, self.add_line)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 5)
sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)
panel.SetSizer(sizer)
bmp = wx.Image("icon.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap()
il = wx.ImageList(16,16)
il.Add(bmp)
self.list_ctrl.AssignImageList(il,wx.IMAGE_LIST_SMALL)
line = "Line %s" % self.index
self.list_ctrl.InsertStringItem(self.index, line,-1)
self.list_ctrl.SetStringItem(self.index, 1, "01/19/2010")
self.list_ctrl.SetStringItem(self.index, 2, "USA")
self.index += 1
self.list_ctrl.InsertStringItem(self.index, line,-1)
self.list_ctrl.SetStringItem(self.index, 1, "01/19/2010")
self.list_ctrl.SetStringItem(self.index, 2, "USA")
#self.list_ctrl.SetItemBackgroundColour(self.index,wx.LIGHT_GREY)
self.index += 1
self.list_ctrl.InsertStringItem(self.index, line,-1)
self.list_ctrl.SetStringItem(self.index, 1, "01/19/2010")
self.list_ctrl.SetStringItem(self.index, 2, "USA")
self.index += 1
#----------------------------------------------------------------------
def add_line(self, event):
if self.index > 0:
image = 1
else:
image = -1
line = "Line %s" % self.index
self.list_ctrl.InsertStringItem(self.index, line,image)
self.list_ctrl.SetStringItem(self.index, 1, "01/19/2010")
self.list_ctrl.SetStringItem(self.index, 2, "USA")
self.index += 1
def onMouseOver(self, event):
print "mouse over"
for item in range(self.list_ctrl.GetItemCount()):
self.list_ctrl.SetItemBackgroundColour(item,wx.NullColor)
x = event.GetX()
y = event.GetY()
item, flags = self.list_ctrl.HitTest((x, y))
self.list_ctrl.SetItemBackgroundColour(item,wx.RED)
#self.list_ctrl.RefreshItems(0,2)
event.Skip()
def onMouseLeave(self, event):
print "mouse leave"
for item in range(self.list_ctrl.GetItemCount()):
self.list_ctrl.SetItemBackgroundColour(item,wx.NullColor)
#self.list_ctrl.RefreshItems(0,2)
event.Skip()
'''
def onMouseOver(self, event): #USED to display tooltip on items that cannot be selected
x = event.GetX()
y = event.GetY()
item, flags = self.list_ctrl.HitTest((x, y))
color = self.list_ctrl.GetItemBackgroundColour(item)
if color == wx.NullColor:
self.list_ctrl.SetItemBackgroundColour(item,wx.RED)
elif color == wx.RED:
item = item - 1
color = self.list_ctrl.GetItemBackgroundColour(item)
self.list_ctrl.SetItemBackgroundColour(item,wx.Nu)
'''
#----------------------------------------------------------------------
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()
다른 사람에게 도움이되기를 바랍니다. 마우스를 놓으면 빨간색에서 기본값으로 변경됩니다. – jellyDean