首页 > 解决方案 > wxPython - UltimateListCtrl 如何在选中项目时突出显示行?

问题描述

我在 UltimateListCtrl 中使用了不同类型的小部件。在某些情况下,我遇到的问题是我需要用它们来填充大部分列表。这使得突出显示一行非常烦人,因为如果您单击一个小部件,该行不会突出显示,因为焦点在小部件上。

如何防止这种情况发生或将焦点传递给行/列表?

这是一个使用示例代码:

import wx
from wx.lib.agw import ultimatelistctrl as ULC

class TestUltimateListCtrlPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS, size=(640,300))

        self.list_ctrl = ULC.UltimateListCtrl(self, -1, agwStyle=ULC.ULC_REPORT|ULC.ULC_HAS_VARIABLE_ROW_HEIGHT)
        self.list_ctrl.InsertColumn(0, "Make")
        self.list_ctrl.InsertColumn(1, "Model")
        self.list_ctrl.InsertColumn(2, "Year")
        self.list_ctrl.InsertColumn(3, "Color")

        rows = [("Ford", "Taurus", "1996", "Blue"),
                ("Nissan", "370Z", "2010", "Green"),
                ("Porche", "911", "2009", "Red")
                ]

        for rowIndex, data in enumerate(rows):
            for colIndex, coldata in enumerate(data):
                if colIndex == 0:
                    self.list_ctrl.InsertStringItem(rowIndex, coldata)
                else:
                     self.tab_st = wx.StaticText(self.list_ctrl, label=coldata)            
                     self.list_ctrl.SetItemWindow(rowIndex, colIndex, self.tab_st, expand=True)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.list_ctrl, 1, wx.ALL|wx.EXPAND, 5)
        self.SetSizer(sizer)


class MyForm(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,None,wx.ID_ANY,size=(640,300),style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN)
        panel = TestUltimateListCtrlPanel(self)

if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm()
    frame.Show()
    app.MainLoop() 

标签: pythonpython-3.xuser-interfacewxpython

解决方案


推荐阅读