Word wrapping in a ListCtrl (or ObjectListView)

若如初见. 提交于 2019-12-11 11:52:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!