A quick question: I'd like to set up a wxListCtrl to avoid having either a horizontal scroll bar or empty space to the right of the last column. Is there any way of doing this, so that the last column in the list automatically resizes itself to take up the remaining space?
There doesn't seem to be any built-in parameter you can pass to wxListCtrl.SetColumnWidth() to allow this to happen, and it seems to me that this would be a fairly common request. I've tried fiddling about with adjusting the size of the columns in response to an EVT_SIZE, but there doesn't seem to be any reliable way of doing this that's cross-platform and allows for the width of the vertical scroll bar if there are too many items to show on-screen at once.
Any suggestions? I wonder if this would be a suitable topic for a cookbook entry?
A quick question: I'd like to set up a wxListCtrl to avoid having either a
horizontal scroll bar or empty space to the right of the last column. Is
there any way of doing this, so that the last column in the list
automatically resizes itself to take up the remaining space?
I don't think there is an automatic way to do it.
There doesn't seem to be any built-in parameter you can pass to
wxListCtrl.SetColumnWidth() to allow this to happen, and it seems to me
that this would be a fairly common request. I've tried fiddling about
with
adjusting the size of the columns in response to an EVT_SIZE, but there
doesn't seem to be any reliable way of doing this that's cross-platform
and
allows for the width of the vertical scroll bar if there are too many
items
to show on-screen at once.
You can get the width of the scrollbar using wxSystemSettings, and the
number of items that fit in the list control with GetCountPerPage. That
should help you in doing the size calculations.
If you feel like organizing it as a mix-in class it would probably make a
good addition to the library.
···
--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters? http://wxPython.org Relax with wxPython!
> A quick question: I'd like to set up a wxListCtrl to avoid having either a
> horizontal scroll bar or empty space to the right of the last column. Is
> there any way of doing this, so that the last column in the list
> automatically resizes itself to take up the remaining space?
I don't think there is an automatic way to do it.
That's what I suspected...
> There doesn't seem to be any built-in parameter you can pass to
> wxListCtrl.SetColumnWidth() to allow this to happen, and it seems to me
> that this would be a fairly common request. I've tried fiddling about
with
> adjusting the size of the columns in response to an EVT_SIZE, but there
> doesn't seem to be any reliable way of doing this that's cross-platform
and
> allows for the width of the vertical scroll bar if there are too many
items
> to show on-screen at once.
You can get the width of the scrollbar using wxSystemSettings, and the
number of items that fit in the list control with GetCountPerPage. That
should help you in doing the size calculations.
If you feel like organizing it as a mix-in class it would probably make a
good addition to the library.
That's a great idea -- I've written a first cut at a mix-in class and put it at:
Let me know what you think -- It has an annoying habit of showing a horizontal scrollbar at odd times, but if you try and scroll the horizontal scrollbar it immediately disappears...I've got no idea why that's happening, or how to make it go away -- but at least the basic mix-in is written.
Oh, I've had to hard-wire a "margin" into the code, which looks good for Windows 2K but may not work as well with other OS's. Any ideas on how to improve this? I guess at worst we may have to put a few "if wxPlatform == ..." statements into the code to allow for different margins in the implementation of wxListCtrl on different platforms.
Anyway, feel free to add this to the library if you think it's ready -- or suggest any other things you'd like me to fix on it first.
Looks pretty good so far. One more thing that it should do is catch the
column resize events and adjust the last column accordingly.
Good idea -- I've actually hidden the column headings in the program I'm working on, so column resizing wasn't an issue for me, but it could certainly be useful for other people.
I've updated the mixin to include an EVT_LIST_COL_END_DRAG handler. MS Windows seems to actually adjust the size of its columns during system idle, so I had to add an idle handler to make it work, but it seems to handle resized columns properly now.
>Looks pretty good so far. One more thing that it should do is catch the
>column resize events and adjust the last column accordingly.
Good idea -- I've actually hidden the column headings in the program I'm
working on, so column resizing wasn't an issue for me, but it could
certainly be useful for other people.
I've updated the mixin to include an EVT_LIST_COL_END_DRAG handler. MS
Windows seems to actually adjust the size of its columns during system
idle, so I had to add an idle handler to make it work, but it seems to
handle resized columns properly now.
Let me know if there's anything else you want me to add...
Looks good. I should be rebuilding on wxGTK later today so I'll give it a
whirl there too. BTW, this is going to end up in the
wxPython.lib.mixins.listctrl module.
···
--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters? http://wxPython.org Relax with wxPython!
Looks good. I should be rebuilding on wxGTK later today so I'll give it a
whirl there too. BTW, this is going to end up in the
wxPython.lib.mixins.listctrl module.
I had to make a few tweaks for wxGTK. You can get the new version from CVS
or at http://cvs.wxwindows.org/cgi-bin/viewcvs.cgi/wxPython/wxPython/lib/mixins/li
stctrl.py. BTW, this will also need the CVS version of wxListCtrl as the
generic one used by wxGTK didn't send the column dragging events until just
a few minutes ago.
···
--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters? http://wxPython.org Relax with wxPython!
I had to make a few tweaks for wxGTK. You can get the new version from CVS
or at http://cvs.wxwindows.org/cgi-bin/viewcvs.cgi/wxPython/wxPython/lib/mixins/li
stctrl.py. BTW, this will also need the CVS version of wxListCtrl as the
generic one used by wxGTK didn't send the column dragging events until just
a few minutes ago.
That looks great. Thanks for testing it out under wxGTK and adjusting the code so it works...I don't have wxPython installed on my Linux machine right now, as I'm only using it for server-side development.