alwbtc
alwbtc

Reputation: 29455

How to make scrollbars appear in a wx.lib.scrolledpanel.ScrolledPanel which has no widgets but only a straight line?

I create a wx.lib.scrolledpanel.ScrolledPanel. I insert it in its parent panel inside a vertical box sizer. Parent panel's size is width=500, height=500.

Then, in ScrolledPanel, I draw a vertical line with a height of 1000. When I run the app, scrollbars are not displayed on ScrolledPanel. I just see my vertical line with a height of 500, because height of parent panel is 500. There are no widgets in scrolledpanel or parent panel.

Why doesn't the vertical scrollbar appear, so that I can scroll down and see the rest of that vertical line? How do I make it appear?

I even try to set the height of ScrolledPanel to 1000 after I draw the vertical line, but it doesn't work either, something like:

this doesn't work:

create_parent_panel_with_height_500()
create_scrolled_panel()
put_scrolled_panel_on_parent_panel_and_set_sizer()
push_a_button_to_draw_the_vertical_line_with_height_1000()
update_and_refresh_scrolled_panel()

this doesn't work either:

create_parent_panel_with_height_500()
create_scrolled_panel()
put_scrolled_panel_on_parent_panel_and_set_sizer()
push_a_button_to_draw_the_vertical_line_with_height_1000()
set_scrolled_panels_height_to_1000()
update_and_refresh_scrolled_panel()

In both methods, scrollbars don't appear after the vertical line is drawn.

Upvotes: 0

Views: 730

Answers (2)

RobinDunn
RobinDunn

Reputation: 6306

Since you don't have any widgets on the panel then a ScrolledPanel is not the best choice since it bases the virtual and physical sizes of the window on the space needed by the sizer. Using a wx.ScrolledWindow would be a better choice, as you can then control the virtual size yourself.

If you are stuck with the ScrolledPanel for some reason, it is still doable. You should just need to create a sizer, and add a spacer to it that reserves enough space for your drawing, and assign the sizer to the panel. There is some code in the ScrolledPanel that expects to have at least one child widget that accepts the focus, but that could probably be dealt with in a derived class if there are any issues from that.

Upvotes: 1

Rolf of Saxony
Rolf of Saxony

Reputation: 22443

As you have not pasted any 'real' code, it's difficult to know what you are doing wrong.
Perhaps this will help:

#!/bin/env python
import wx
import wx.lib.scrolledpanel as SP
class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, - 1, "Frame", size=(300, 300))
        panel = wx.Panel(self, - 1)
        self.scrolledPanel = AScrollPanel(panel)
        panel.Show()

class AScrollPanel(SP.ScrolledPanel):
    def __init__(self, parent):
        SP.ScrolledPanel.__init__(self, parent, -1, size=(200, 100))
        self.parent = parent
        self.Sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self.Sizer)
        self.SetupScrolling(scroll_x=True, scroll_y=True, scrollToTop=False)
        self.ATop = wx.StaticText(self, -1, "Top of Line")
        self.ALine = wx.StaticLine(self, -1, size=(30,1000),style=wx.LI_VERTICAL)
        self.ABottom = wx.StaticText(self, -1, "Bottom of Line")
        self.Sizer.Add(self.ATop)
        self.Sizer.Add(self.ALine)
        self.Sizer.Add(self.ABottom)
        self.Layout()

if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame()
    frame.Show(True)
    app.MainLoop() 

Upvotes: 0

Related Questions