问题
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?
回答1:
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()
回答2:
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.
来源:https://stackoverflow.com/questions/4733549/word-wrapping-in-a-listctrl-or-objectlistview