我在 macOS 上,所以不能使用 SetHeaderAttr。
相反,我试图使用 headerctrl 而不是本机标题,因为我正在尝试更改标题的颜色。我希望它能够单击标题来对数据进行排序等。但是我不知道如何将其作为我的 ListCtrl 的一部分来实现。
我想知道是否有人对此有任何经验,并且可以对此提供一些见解。提前致谢。
这是我目前拥有的:
class MyHeaderCtrl(wx.HeaderCtrl):
def __init__(self, parent):
super(MyHeaderCtrl, self).__init__(parent, style=wx.BORDER_NONE)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.SetBackgroundColour(wx.Colour(0, 0, 255))
def OnPaint(self, event):
radius = 8
dc = wx.AutoBufferedPaintDC(self)
gc = wx.GraphicsContext.Create(dc)
x, y, width, height = self.GetClientRect()
path = gc.CreatePath()
path.AddRoundedRectangle(x, y, width, height, radius)
gc.SetBrush(wx.Brush(self.GetBackgroundColour()))
gc.FillPath(path)
class MyListCtrl(wx.ListCtrl):
def __init__(self, parent):
wx.ListCtrl.__init__(self, parent, style=wx.LC_REPORT)
self.header_ctrl = MyHeaderCtrl(self)
self.header_ctrl.Bind(wx.EVT_HEADER_CLICK, self.OnHeaderClick)
self.InsertColumn(0, "col1")
self.InsertColumn(1, "col2")
self.InsertItem(0, "data1")
self.SetItem(0, 1, "data1")
self.InsertItem(1, "data2")
self.SetItem(1, 1, "data2")
self.InsertItem(2, "data3")
self.SetItem(2, 1, "data3")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.header_ctrl, 0, wx.EXPAND)
self.SetSizer(sizer)