ListCtrl(或 ObjectListView)中的自动换行 [英] Word wrapping in a ListCtrl (or ObjectListView)

查看:19
本文介绍了ListCtrl(或 ObjectListView)中的自动换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 wxListCtrl(实际上它是一个 ObjectListView),用 LC_REPORT 设置了两个列.

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?

推荐答案

使用 ObjectListView 是不可能的(请参阅他们的 FAQ),因为 ListCtrl 不支持多行输入.

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

但是,可以使用 UltimateListCtrl

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()

这篇关于ListCtrl(或 ObjectListView)中的自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆