Making ScrolledPanel scroll only vertically?

I’ve got a ScrolledPanel whose children I do not want to grow past the visual width of the panel, but I do want to allow them to be scrolled vertically. (I believe that is to say, I want its virtual width to match its client width?) However, disabling horizontal scroll doesn’t seem to stop sizers from giving items as much horizontal space as they want. Is there some method to do this that I’m not seeing and/or event handling trickery to do this?

Thanks,

Steven

Please make a small simple runnable sample application that shows what you are trying to do. MakingSampleApps - wxPyWiki. Also using the WIT may help: http://wiki.wxpython.org/Widget_Inspection_Tool

···

On 5/17/12 10:26 AM, Steven Wallace wrote:

I've got a ScrolledPanel whose children I do not want to grow past the
visual width of the panel, but I do want to allow them to be scrolled
vertically. (I believe that is to say, I want its virtual width to match
its client width?) However, disabling horizontal scroll doesn't seem to
stop sizers from giving items as much horizontal space as they want. Is
there some method to do this that I'm not seeing and/or event handling
trickery to do this?

--
Robin Dunn
Software Craftsman

In the attached file, the text will wordwrap to the size of the frame in a Panel, but not in a ScrolledPanel. I presume that’s because the text widget was only given as much horizontal space as the frame had for the panel, but given unlimited for the scrolled panel. I would like the scrolled panel to followthe panel’s behavior for horizontal space.

Thanks,

Steven

scroll.py (688 Bytes)

···

On Friday, May 18, 2012 12:04:02 PM UTC-5, Robin Dunn wrote:

On 5/17/12 10:26 AM, Steven Wallace wrote:

I’ve got a ScrolledPanel whose children I do not want to grow past the

visual width of the panel, but I do want to allow them to be scrolled

vertically. (I believe that is to say, I want its virtual width to match

its client width?) However, disabling horizontal scroll doesn’t seem to

stop sizers from giving items as much horizontal space as they want. Is

there some method to do this that I’m not seeing and/or event handling

trickery to do this?

Please make a small simple runnable sample application that shows what
you are trying to do. http://wiki.wxpython.org/MakingSampleApps. Also
using the WIT may help: http://wiki.wxpython.org/Widget_Inspection_Tool


Robin Dunn

Software Craftsman

http://wxPython.org

It's because the ScrolledPanel is setting the virtual size based on the minimum size calculated by the sizer, and that is based on the best size reported by the static text. So since the best size of a static text is based on how much space it takes to show the text without wrapping then that is what you get. Passing scroll_x=False just means don't show that scrollbar, it has nothing to do with the virtual size of the scrolled window or the layout of the widgets.

You can try resetting the virtual size of the scrolled panel, although it wasn't designed with that in mind so there may be some glitches. You can set the min width of the static text to be your desired width, then the sizer will use that value instead of the best width. Or you can use wx.ScrolledWindow instead of ScrolledPanel, and set the virtual size and etc. how you prefer it.

···

On 5/19/12 8:14 AM, Steven Wallace wrote:

In the attached file, the text will wordwrap to the size of the frame in
a Panel, but not in a ScrolledPanel. I presume that's because the text
widget was only given as much horizontal space as the frame had for the
panel, but given unlimited for the scrolled panel. I would like the
scrolled panel to followthe panel's behavior for horizontal space.

--
Robin Dunn
Software Craftsman