繁体   English   中英

wx.ListCtrl问题

[英]Problems with wx.ListCtrl

这是一个片段

    self.list_ctrl = wx.ListCtrl(self, size=(-1,100),
                     style=wx.LC_ICON|wx.LC_ALIGN_LEFT
                     )
    il = wx.ImageList(16,16,True)
    png = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN,wx.ART_OTHER, (16,16))
    il.Add(png)
    self.list_ctrl.AssignImageList(il,wx.IMAGE_LIST_NORMAL)


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

    self.list_ctrl.InsertImageStringItem(0,"1",0)
    self.list_ctrl.InsertImageStringItem(1,"2",0)

我的问题是图标出现在文本的顶部,这不应该发生,因为我在样式中添加了wx.LC_ALIGN_LEFT 我希望图标显示在文本的左侧。

另一个问题是,我希望每行一个元素。 在我的代码中,几乎就像每列一个元素。

任何人都可以帮助我解决这些问题吗? 谢谢。

在wxPython演示ListCtrl上,看起来他们使用SetImageList()而不是AssignImageList()。 不知道有什么区别。 我看不到您要在何处插入任何文本。 您需要使用SetStringItem将文本放入我所看到的其他列中。

编辑:来自wxPython演示包,ListCtrl演示的代码:

self.il = wx.ImageList(16, 16)

self.idx1 = self.il.Add(images.Smiles.GetBitmap())
self.sm_up = self.il.Add(images.SmallUpArrow.GetBitmap())
self.sm_dn = self.il.Add(images.SmallDnArrow.GetBitmap())

然后我们将数据/图像添加到小部件

def PopulateList(self):
    if 0:
        # for normal, simple columns, you can add them like this:
        self.list.InsertColumn(0, "Artist")
        self.list.InsertColumn(1, "Title", wx.LIST_FORMAT_RIGHT)
        self.list.InsertColumn(2, "Genre")
    else:
        # but since we want images on the column header we have to do it the hard way:
        info = wx.ListItem()
        info.m_mask = wx.LIST_MASK_TEXT | wx.LIST_MASK_IMAGE | wx.LIST_MASK_FORMAT
        info.m_image = -1
        info.m_format = 0
        info.m_text = "Artist"
        self.list.InsertColumnInfo(0, info)

        info.m_format = wx.LIST_FORMAT_RIGHT
        info.m_text = "Title"
        self.list.InsertColumnInfo(1, info)

        info.m_format = 0
        info.m_text = "Genre"
        self.list.InsertColumnInfo(2, info)

    items = musicdata.items()
    for key, data in items:
        index = self.list.InsertImageStringItem(sys.maxint, data[0], self.idx1)
        self.list.SetStringItem(index, 1, data[1])
        self.list.SetStringItem(index, 2, data[2])
        self.list.SetItemData(index, key)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM