面板内的 ScrolledPanel 未调整大小

发布于 2024-12-10 02:04:27 字数 748 浏览 1 评论 0原文

我已经玩弄这个有一段时间了,但似乎无法弄清楚。 self.panel = wx.Panel(self, wx.ID_ANY)

我在不滚动的面板内有一个scrolledPanel。

self.panel = wx.Panel(self, wx.ID_ANY)
self.stepPanel = wxscrollpanel.ScrolledPanel(self.panel, -1, style=wx.EXPAND)
self.stepPanel.SetupScrolling(scrollToTop=False)

sizer = wx.BoxSizer(wx.VERTICAL)
self.stepPanel.SetSizerAndFit(sizer)

更新功能是这样的...

sizer = self.stepPanel.GetSizer()
# Add some widgets
self.stepPanel.SetSizerAndFit(sizer)

当用户单击按钮时,我稍后将小部件添加到大小调整器...我尝试过自动布局,FitInside(),Update() ...似乎无法滚动此stepPanel当我添加小部件时。

编辑:添加更多信息...

这里的想法是 self.panel 顶部有一个不滚动的区域(只是另一个面板),而下部部分滚动(self.stepPanel),但看起来 stepPanel生长在 self.panel 的可视区域之外

编辑:已解决,请参阅评论。

I've been toying with this for a while and just can't seem to figure it out.
self.panel = wx.Panel(self, wx.ID_ANY)

I have a scrolledPanel inside a panel that does not scroll.

self.panel = wx.Panel(self, wx.ID_ANY)
self.stepPanel = wxscrollpanel.ScrolledPanel(self.panel, -1, style=wx.EXPAND)
self.stepPanel.SetupScrolling(scrollToTop=False)

sizer = wx.BoxSizer(wx.VERTICAL)
self.stepPanel.SetSizerAndFit(sizer)

Update function goes like this ...

sizer = self.stepPanel.GetSizer()
# Add some widgets
self.stepPanel.SetSizerAndFit(sizer)

I add widgets to the sizer later on when the user clicks a button ... I've tried auto layout, FitInside(), Update() ... can't seem to scroll this stepPanel when I add widgets.

EDIT: Adding more info ...

The idea here is that the self.panel has an area at the top that does not scroll (just another panel), while the lower portion scrolls (self.stepPanel), but it appears that the stepPanel grows off of the viewable area of the self.panel

EDIT: Solved see comment.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掩于岁月 2024-12-17 02:04:27

我想我明白了。像往常一样,在添加或删除小部件时,您需要在父级上调用 Layout,在本例中,父级是正在获取新子级的滚动面板。您还必须调用SetupScrolling(),以便它可以重新计算有多少空间以及是否需要滚动条。这是一个在 Windows 上适用于我的示例:

import wx
import wx.lib.scrolledpanel as scrolled

########################################################################
class MyForm(wx.Frame):

    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial", size=(200,500))

        # Add a panel so it looks the correct on all platforms
        self.panel = wx.Panel(self, wx.ID_ANY)

        # --------------------
        # Scrolled panel stuff
        self.scrolled_panel = scrolled.ScrolledPanel(self.panel, -1, 
                                 style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="panel1")
        self.scrolled_panel.SetAutoLayout(1)
        self.scrolled_panel.SetupScrolling()

        words = "A Quick Brown Insane Fox Jumped Over the Fence and Ziplined to Cover".split()
        self.spSizer = wx.BoxSizer(wx.VERTICAL)
        for word in words:
            text = wx.TextCtrl(self.scrolled_panel, value=word)
            self.spSizer.Add(text)
        self.scrolled_panel.SetSizer(self.spSizer)
        # --------------------

        btn = wx.Button(self.panel, label="Add Widget")
        btn.Bind(wx.EVT_BUTTON, self.onAdd)

        panelSizer = wx.BoxSizer(wx.VERTICAL)
        panelSizer.AddSpacer(50)
        panelSizer.Add(self.scrolled_panel, 1, wx.EXPAND)
        panelSizer.Add(btn)
        self.panel.SetSizer(panelSizer)

    #----------------------------------------------------------------------
    def onAdd(self, event):
        """"""
        print "in onAdd"
        new_text = wx.TextCtrl(self.scrolled_panel, value="New Text")
        self.spSizer.Add(new_text)
        self.scrolled_panel.Layout()
        self.scrolled_panel.SetupScrolling()

# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm().Show()
    app.MainLoop()

I think I figured it out. As usual, when adding or deleting widgets, you need to call Layout on the parent, which in this case is the scrolled panel that is getting new children. You also have to call SetupScrolling() so it can recalculate how much space there is and whether or not it needs scrollbars. Here's an example that works for me on Windows:

import wx
import wx.lib.scrolledpanel as scrolled

########################################################################
class MyForm(wx.Frame):

    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial", size=(200,500))

        # Add a panel so it looks the correct on all platforms
        self.panel = wx.Panel(self, wx.ID_ANY)

        # --------------------
        # Scrolled panel stuff
        self.scrolled_panel = scrolled.ScrolledPanel(self.panel, -1, 
                                 style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="panel1")
        self.scrolled_panel.SetAutoLayout(1)
        self.scrolled_panel.SetupScrolling()

        words = "A Quick Brown Insane Fox Jumped Over the Fence and Ziplined to Cover".split()
        self.spSizer = wx.BoxSizer(wx.VERTICAL)
        for word in words:
            text = wx.TextCtrl(self.scrolled_panel, value=word)
            self.spSizer.Add(text)
        self.scrolled_panel.SetSizer(self.spSizer)
        # --------------------

        btn = wx.Button(self.panel, label="Add Widget")
        btn.Bind(wx.EVT_BUTTON, self.onAdd)

        panelSizer = wx.BoxSizer(wx.VERTICAL)
        panelSizer.AddSpacer(50)
        panelSizer.Add(self.scrolled_panel, 1, wx.EXPAND)
        panelSizer.Add(btn)
        self.panel.SetSizer(panelSizer)

    #----------------------------------------------------------------------
    def onAdd(self, event):
        """"""
        print "in onAdd"
        new_text = wx.TextCtrl(self.scrolled_panel, value="New Text")
        self.spSizer.Add(new_text)
        self.scrolled_panel.Layout()
        self.scrolled_panel.SetupScrolling()

# Run the program
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyForm().Show()
    app.MainLoop()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文