如何使 wxListCtrl 使用本机 macos 实现?

How do I make wxListCtrl use the native macos implementation?

我试图让我的 wxListCtrl 在 macOS 上使用本机实现,但我只获得了通用实现。

根据wxWiki

Starting with wxWidgets 2.8 (wxMac), wxListCtrl uses a native implementation for report mode, and uses a generic implementation for other modes.

我已经将我的 wxListCtrl 设置为 LC_REPORT,但我仍然得到通用实现。

我做错了什么?

(我在 macOS 10.15.4 Catalina 上使用 Python 3.8.2,并使用稳定的 wxPython 4.0.7 和最新的快照版本 wxPython-4.1.0a1.dev4650+de25f309-cp38-cp38-macosx_10_9_x86_64.whl 进行了测试)


最小示例

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import wx

class MyForm(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, 'Example')

        panel = wx.Panel(self, wx.ID_ANY)
        self.index = 0

        self.list_ctrl = wx.ListCtrl(panel, style=wx.LC_REPORT)
        self.list_ctrl.InsertColumn(0, 'Title')

        btn = wx.Button(panel, label='Add row')
        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)

    def add_line(self, event):
        line = "Row %s" % self.index
        self.list_ctrl.InsertItem(self.index, line)
        self.index += 1


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

Mac 下的原生​​ wxListCtrl 实现被证明问题太大,因此在 wx 3 中被删除。如果可以,考虑使用 wxDataViewCtrl,它是 [=] 下原生的15=] 并且通常可用,即使由于本机 API 特性,与通用版本相比它仍然有一些限制。