如果我设置的第一列的格式中一个的ListCtrl到对准中心(或右对齐)没有反应。它适用于其它列。

这仅发生在Windows - 我已经测试它在Linux上,它工作正常。 没有人知道,如果有一个工作轮或其他解决方案?

下面是基于在 http://zetcode.com/wxpython/ 找到的码的示例

import wx
import sys

packages = [('jessica alba', 'pomona', '1981'), ('sigourney weaver', 'new york',    '1949'),
    ('angelina jolie', 'los angeles', '1975'), ('natalie portman', 'jerusalem', '1981'),
    ('rachel weiss', 'london', '1971'), ('scarlett johansson', 'new york', '1984' )]

class Actresses(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(380, 230))

        hbox = wx.BoxSizer(wx.HORIZONTAL)
        panel = wx.Panel(self, -1)

        self.list = wx.ListCtrl(panel, -1, style=wx.LC_REPORT)
        self.list.InsertColumn(0, 'name', wx.LIST_FORMAT_CENTRE,width=140)
        self.list.InsertColumn(1, 'place', wx.LIST_FORMAT_CENTRE,width=130)
        self.list.InsertColumn(2, 'year', wx.LIST_FORMAT_CENTRE, 90)

        for i in packages:
            index = self.list.InsertStringItem(sys.maxint, i[0])
            self.list.SetStringItem(index, 1, i[1])
            self.list.SetStringItem(index, 2, i[2])

        hbox.Add(self.list, 1, wx.EXPAND)
        panel.SetSizer(hbox)

        self.Centre()
        self.Show(True)

app = wx.App()
Actresses(None, -1, 'actresses')
app.MainLoop()
有帮助吗?

解决方案

我已经发现,该作品(通知我开始插入的列1,而不是0):

    self.list = wx.ListCtrl(panel, -1, style=wx.LC_REPORT)
    self.list.InsertColumn(1, 'name', wx.LIST_FORMAT_CENTRE,width=140)
    self.list.InsertColumn(2, 'place', wx.LIST_FORMAT_CENTRE,width=130)
    self.list.InsertColumn(3, 'year', wx.LIST_FORMAT_CENTRE, 90)

不知道为什么这个工程,但它确实。我们希望,将有来自这样做没有影响。

由于robots.jpg对振奋的想法。

其他提示

视窗绝对不同对待的第一列。一个解决方法是创建一个空的列0和隐藏:

class Actresses(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(380, 230))
        #...

        self.list = wx.ListCtrl(panel, -1, style=wx.LC_REPORT)
        self.list.InsertColumn(0, '', width=0)
        self.list.InsertColumn(1, 'name', wx.LIST_FORMAT_CENTRE,width=140)
        self.list.InsertColumn(2, 'place', wx.LIST_FORMAT_CENTRE,width=130)
        self.list.InsertColumn(3, 'year', wx.LIST_FORMAT_CENTRE, width=90)

        for i in packages:
            index = self.list.InsertStringItem(sys.maxint, '')
            self.list.SetStringItem(index, 1, i[0])
            self.list.SetStringItem(index, 2, i[1])
            self.list.SetStringItem(index, 3, i[2])

        # catch resize event
        self.list.Bind(wx.EVT_LIST_COL_BEGIN_DRAG, self.OnColDrag)
        #...

    def OnColDrag(self, evt):
        if evt.m_col == 0:
            evt.Veto()

我不认为从这样做任何重大的副作用,但让我知道,如果我错了。我想,它假定在第一列中的有用数据将不再有用GetItemText()或其他任何东西。

编辑 - 添加的代码,以防止调整列0

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top