你可以使它與UltimateListCtrl。
以下代碼請參考this,並做了一些改進以支持colum拖動的自動更新。
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)
self.items = ['list', 'list', 'I want to wrap words and content shold be placed in multiple lines for each item as the window is resized']
colWidth = 200
self.colWidthPad = 5
self.list.InsertColumn(0, "test", width=colWidth)
for item in self.items[::-1]:
item = wordwrap(item, colWidth - self.colWidthPad, wx.ClientDC(self))
self.list.InsertStringItem(0, item)
self.list.Bind(wx.EVT_LIST_COL_DRAGGING, self.onDrag)
def onDrag(self, evt):
col = evt.GetItem().GetColumn()
width = self.list.GetColumnWidth(col)
itemCount = self.list.GetItemCount()
for i in range(0, itemCount):
text = wordwrap(self.items[i], width - self.colWidthPad, wx.ClientDC(self))
self.list.SetStringItem(i, col, text)
app = wx.App(False)
frm = Frame(None, title="ULC wordwrap test")
frm.Show()
app.MainLoop()
我發現這OSX下的不可靠:https://www.dropbox.com/s/iyaaypm4e9o8mf6/Screenshot%202014-02-20%2020.04.39.png HTTPS://www.dropbox。 com/s/kt4o2ehw4qrkc1h /截圖%202014-02-20%2020.06.43.png https://www.dropbox.com/s/wpxw3z1w3l8i35p/Screenshot%202014-02-20%2020.08.12.png – GreenAsJade
@GreenAsJade I沒有OSX環境,你可以請幫忙嘗試一下在onDrag()中調用self.list.Refresh()? –
當然。它似乎沒有明顯的幫助。只要我將左欄大小設置爲「我想要」的寬度,我就會得到...... s在稍大的寬度上,我可以將頂部或底部切掉。在「合理」的寬度,它看起來很好。 – GreenAsJade