0

我正在尝试使用向列表框添加多行消息

wx.listbox.Append('part1 \r\n part2')

在 linux (gtk) 上我得到多行框

在 Windows (msw) 上它只是忽略换行符......

有没有办法在 Windows 中获得类似的功能?

4

2 回答 2

2

The windows ListBox control doesn't implement that behavior. While it allows drawing the item yourself and adjusting its height, wxWidgets doesn't expose this functionality for the ListBox. As an alternative, you could use the wx.SimpleHtmlListBox or derive from wx.HtmlListBox.

wxSimpleHtmlListBox is an implementation of wxHtmlListBox which shows HTML content in the listbox rows.

Unlike wxHtmlListBox, this is not an abstract class and thus it has the advantage that you can use it without deriving your own class from it. However, it also has the disadvantage that this is not a virtual control and thus it's not well-suited for those cases where you need to show a huge number of items: every time you add/insert a string, it will be stored internally and thus will take memory.

It inherits from the ItemContainer just like wx.ListBox, so the usage is essentially the same. Keep in mind that you have to escape certain characters (as shown in the example). For that you could use cgi.escape.

import wx
import cgi

class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,None)
        lb = wx.SimpleHtmlListBox(self)
        lb.Append( cgi.escape("foo <&> bar") )
        lb.Append("<b>Line 1</b> <br> Line 2")
        
app = wx.PySimpleApp()
frame = MyFrame().Show()
app.MainLoop()
于 2012-10-29T21:11:39.673 回答
0

我对此表示怀疑。本机小部件可能不支持 Windows 上的这种行为。不过,您也许可以使用 DVC_CustomRenderer 来完成(2.9 系列中的新功能)。我知道您可以使用 UltimateListCtrl 来做到这一点,因为演示本身就表明了这一点。如果它是必备功能,我会建议走这条路线。

于 2012-10-29T17:35:26.240 回答