Search code examples
c++scrollscrollbarwxwidgets

How to Scroll Parent wxScrollWindow from Inside Child wxScrollWindow in wxWidgets


Hi i am using wxScrollWindow and have 2 wxScrollWindows. Both of them works correctly individually.

  1. First wxScrolledWindow scrolls horizontally, and the second scrollWindow scrolls vertically.
  2. First wxScrolledWindow has the second scrolledwindow embedded inside it. Screenshot for illustration purposes is attached below.

The problem is that when I am inside the second scrolled window(vertically) then I am unable to scroll horizontally. In the screenshot the second scroll window contains buttons ranging from button1 to button20 lets say. So I am able to scroll vertically through these buttons. Similarly the first scrolledwindow has many wxPanels that are horizontally scrollable. The problem comes when I try to scroll horizontally when the cursor is on top of any of the buttons. So to scroll horizontally I have to first move the cursor to any of the labels(shown in screenshot as label1 upto label5) and then start horizontal scrolling. How can I also enable horizontal scrolling when the cursor is on top of any of the buttons. I am thinking of forwarding the child scroll event to parent(first) scrollwindow using event.Skip() but I don't know for sure how that will work. The buttons shown in the screenshot are inside a wxScrolledWindow which scrolls only vertically. So when the user tries to scroll the buttons horizontally they don't move as expected. But i want that the parent scrollwindow should be moving(scrolling) when the user tries to scroll the buttons horizontally.

illustration


Solution

  • I have resolved the issue by writing my own custom event class which derived from wxEvent and everything is working now as expected. That is, I am able to control the scrolling of the parent scrollwindow(horizontal) from within the child scrollwindow(vertical).