Making ScrolledPanel scroll only vertically?

136 views
Skip to first unread message

Steven Wallace

unread,
May 17, 2012, 1:26:31 PM5/17/12
to wxpytho...@googlegroups.com
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

Robin Dunn

unread,
May 18, 2012, 1:04:02 PM5/18/12
to wxpytho...@googlegroups.com
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

Steven Wallace

unread,
May 19, 2012, 11:14:39 AM5/19/12
to wxpytho...@googlegroups.com
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

Robin Dunn

unread,
May 21, 2012, 1:10:13 PM5/21/12
to wxpytho...@googlegroups.com
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.

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.
Reply all
Reply to author
Forward
0 new messages