如何设置和保留最小宽度?
我在 wx.LC_REPORT 模式下使用一些 wx.ListCtrl 类,并用 ListCtrlAutoWidthMixin 进行增强。
问题是:当用户双击列分隔符(以自动调整列大小)时,列宽设置为与内容宽度匹配。 这是由 wx 库完成的,当控件为空时,将列大小调整为几个像素。
我尝试打电话
self.SetColumnWidth(colNumber, wx.LIST_AUTOSIZE_USEHEADER)
在创建列表时,但它只是设置初始列宽度,而不是允许的最小宽度。
有人成功设置列最小宽度吗?
编辑:尝试捕捉
wx.EVT_LEFT_DCLICK
但没有成功。 当用户双击列分隔符时,不会生成此事件。 还尝试
wx.EVT_LIST_COL_END_DRAG
生成此事件,通常两次,用于双击,但我不知道如何检索有关新大小的信息,或如何区分双击和拖放。 有人还有其他想法吗?
I use some wx.ListCtrl classes in wx.LC_REPORT mode, augmented with ListCtrlAutoWidthMixin.
The problem is: When user double clicks the column divider (to auto resize column), column width is set to match the width of contents. This is done by the wx library and resizes column to just few pixels when the control is empty.
I tried calling
self.SetColumnWidth(colNumber, wx.LIST_AUTOSIZE_USEHEADER)
while creating the list, but it just sets the initial column width, not the minimum allowed width.
Anyone succeeded with setting column minimal width?
EDIT: Tried catching
wx.EVT_LEFT_DCLICK
with no success. This event isn't generated when user double clicks column divider. Also tried with
wx.EVT_LIST_COL_END_DRAG
this event is generated, usually twice, for double click, but I don't see how can I retrieve information about new size, or how to differentiate double click from drag&drop. Anyone has some other ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
老实说,我已经停止使用本机 wx.ListCtrl,转而使用 ObjectListView。 有一点学习曲线,但有很多例子。 这会对您的问题感兴趣。
Honestly, I've stopped using the native wx.ListCtrl in favor of using ObjectListView. There is a little bit of a learning curve, but there are lots of examples. This would be of interest to your question.
好吧,经过一番努力,我找到了解决方法。 从设计的角度来看它很丑,但对我来说已经足够好了。
这就是它的工作原理:
存储列的初始宽度。
注册更新 UI 事件的处理程序。
并编写处理函数。
self.GetColumnCount() - 1 是故意的,因此最后一列的大小不会调整。 我知道这不是一个优雅的解决方案,但它对我来说足够好 - 你不能通过双击分隔线(事实上 - 你根本不能这样做)并在之后双击分隔线来使列太小最后一列调整最后一列的大小以适合列表控件的宽度。
不过,如果有人知道更好的解决方案,请发布。
Ok, after some struggle I got working workaround for that. It is ugly from design point of view, but works well enough for me.
That's how it works:
Store the initial width of column.
Register handler for update UI event.
And write the handler function.
The self.GetColumnCount() - 1 is intentional, so the last column is not resized. I know this is not an elegant solution, but it works well enough for me - you can not make columns too small by double clicking on dividers (in fact - you can't do it at all) and double-clicking on the divider after last column resizes the last column to fit list control width.
Still, if anyone knows better solution please post it.