如何获取 wx.ListCtrl 的宽度及其列名?
我正在 wx.Python 中工作,我想让 wx.ListCtrl 的列自动调整大小,即至少达到列名称的宽度,否则与最宽的元素或其列名称一样宽。 起初我以为 ListCtrlAutoWidthMixin 可能会这样做,但事实并非如此,所以看起来我可能必须自己做(如果有内置的方法可以做到这一点,请纠正我!!!)
我怎样才能知道我的列表的标题和元素会被渲染吗?
I'm working in wx.Python and I want to get the columns of my wx.ListCtrl to auto-resize i.e. to be at minimum the width of the column name and otherwise as wide as the widest element or its column name. At first I thought the ListCtrlAutoWidthMixin might do this but it doesn't so it looks like I might have to do it myself (Please correct me if there's a built in way of doing this!!!)
How can I find out how wide the titles and elements of my list will be rendered?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
除了 jakepars 答案之外:这应该检查标题是否更大,或者在列中占用最多空间的项目。 不优雅但工作...
In Addition to jakepars answer: this should check, whether the header is bigger, or the item which takes the most space in the column. Not to elegant but working...
如果您想避免与 wx.ListCtrl 相关的很多麻烦,您应该转而使用 ObjectListView< /a> (有一本很好的食谱和代码示例论坛)。 它非常好,我倾向于将它用于除非常基本的 ListCtrl 以外的任何用途,因为它非常强大、灵活且易于编码。 这是与之相关的wxPyWiki 页面(包括示例代码)。 开发人员也在 wxPython 邮件列表中,因此您可以通过电子邮件提出问题。
If you'd like to save yourself a lot of headache related to wx.ListCtrl you should switch over to using ObjectListView (has a nice cookbook and forum for code examples). It's very nice and I tend to use it for anything more than a very basic ListCtrl, because it is extremely powerful and flexible and easy to code up. Here's the wxPyWiki page related to it (including example code). The developer is also on the wxPython mailing list so you can email with questions.
是的,你必须自己为 wx.ListCtrl 做这个,我不确定做对是否容易(或优雅)。
考虑使用 wx.Grid,这里有一个小例子可以帮助您:
Yes, you would have to make this yourself for wx.ListCtrl and I'm not sure it would be easy (or elegant) to do right.
Consider using a wx.Grid, here is a small example to get you going:
这对我有用
This works for me