Word wrapping in a ListCtrl (or ObjectListView)

2019-08-01 19:48发布

I have a wxListCtrl (Actually it's an ObjectListView), set with LC_REPORT with two columns.

Is it possible to word wrap the first column of text when it reaches the end of the column?

2条回答
老娘就宠你
2楼-- · 2019-08-01 20:10

It's not possible with a ObjectListView (see their FAQ), because ListCtrl doesn't support multiline entries.

It is possible, however, using UltimateListCtrl

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

class Frame(wx.Frame):
    def __init__(self, *args, **kw):
        wx.Frame.__init__(self, *args, **kw)

        self.list = ULC.UltimateListCtrl(self, agwStyle=ULC.ULC_REPORT|ULC.ULC_HAS_VARIABLE_ROW_HEIGHT)
        items = ['A', 'b', 'a really really long line that if would be nice if it could word-wrap']
        colWidth = 100
        self.list.InsertColumn(0, "AA", width=colWidth)
        for item in items:
            item = wordwrap(item, colWidth, wx.ClientDC(self))
            self.list.InsertStringItem(0, item)

app = wx.App(False)
frm = Frame(None, title="ULC wordwrap test")
frm.Show()
app.MainLoop()
查看更多
Anthone
3楼-- · 2019-08-01 20:16

wxListCtrl is fairly limited in its features. In order to do anything more than the basic, you should consider 'upgrading' to wxGrid, which has a wealth of features.

查看更多
登录 后发表回答