wx.lib.agw.ultimatelistctrl。禁止增加元素的高度

时间:2018-12-28 09:10:56

标签: python python-3.x wxpython python-3.4 wxpython-phoenix

有一个对象UltimateListCtrl

from wx.lib.agw import ultimatelistctrl as ULC

self._ulc_graphs = ULC.UltimateListCtrl(self, size = (-1, 150),
    agwStyle=wx.LC_REPORT|wx.LC_VRULES|wx.LC_HRULES|ULC.ULC_HAS_VARIABLE_ROW_HEIGHT|ULC.ULC_SINGLE_SEL)

此列表包含六列。最后一栏“评论”。由于此对象不允许直接编辑第n列中的元素值(只能编辑第0列)。决定在最后一列的每一行中插入一个按钮,单击该按钮会显示一个带有wx.TextCtrl的对话框。用户在此处输入评论,单击“确定”,然后在列表中第n个项目的最后一栏中输入评论的文本。第五列(如果为0):

self._ulc_graphs.InsertColumn(5, 'Комментарий', ULC.ULC_FORMAT_CENTER, 100)

# in the loop I add rows to the list
self._ulc_graphs.SetStringItem (self._ulc_graphs_index, 5, '')
button_comment = wx.Button(self._ulc_graphs, -1, '...', size=(23, 23))
self._ulc_graphs.SetItemWindow(self._ulc_graphs_index, 5, button_comment, False)
button_comment.Bind(wx.EVT_BUTTON, self.OnButtonComment)
self._ulcItem_btn[self._ulc_graphs_index] = button_comment

结果:

enter image description here

当然,强迫用户将文本写成一行是一个坏主意。因此,我为wx.TextCtrl对象包括了wx.TE_MULTILINE样式。但是,当我在列表单元格中插入多行文本时,此单元格会增加其大小:元素高度=文本中的行数。

当然看起来很糟糕

enter image description here

我可以以某种方式禁止它(增高)吗?

1 个答案:

答案 0 :(得分:1)

我可能误解了您的问题,但是为什么不简单地替换对话框结果中的所有换行符呢?
遵循以下原则:

def OnButtonComment(self,event):
    dlg = wx.TextEntryDialog(self, "Comment", caption="Input Data",
            value="", style=wx.OK|wx.CANCEL|wx.TE_MULTILINE)
    dlg.ShowModal()
    txt = dlg.GetValue()
    txt = txt.replace('\n',' ')
    self.list.SetStringItem(self.index, 1, txt)