The wx.lib.scrolledpanel seems to support mouse wheel vertical scrolling by default, but does not support horizontal scrolling while shift is pressed. I cannot find any way to activate it. Is it even somewhere or should I write an appropriate event handler by myself? How to do that, if so?
wxPython horizontal scrolling with shift+mouse wheel
595 Views Asked by Marcin Pietrzak At
3
There are 3 best solutions below
0
On
It seems that you can use the wx.EVT_SCROLLWIN event, and make sure it calls a simple method which sets the event's orientation to wx.HORIZONTAL (when you have pressed shift.)
sw = wx.ScrolledWindow(p, style = wx.HSCROLL)
def onScroll(event):
event.SetOrientation(wx.HORIZONTAL)
event.Skip()
sw.Bind(wx.EVT_SCROLLWIN, onScroll)
This will make the scroll window scroll in the horizontal direction when you scroll "in it" with the mouse wheel. Here's a quick code you can paste in the console.
app = wx.App()
f = wx.Frame(None)
p = wx.Panel(f)
sw = wx.ScrolledWindow(p)
sw.SetScrollbars(20,20,500,500)
bb = wx.Button(sw, label='big button', pos=(0,0), size=(500,500))
def onScroll(event):
event.SetOrientation(wx.HORIZONTAL)
event.Skip()
sw.Bind(wx.EVT_SCROLLWIN, onScroll)
sz = wx.BoxSizer(wx.HORIZONTAL)
sz.Add(sw, 1, wx.EXPAND)
p.SetSizer(sz)
sz.Fit(f)
f.Show(); app.MainLoop()
0
On
This is a better answer in 2022.
Use Bind(wx.EVT_MOUSEWHEEL) and then in the handler for the event:wx.MouseEvent do
if event.shiftDown:
event.SetWheelAxis(wx.MOUSE_WHEEL_HORIZONTAL)
event.Skip()
To scroll horizontally you must position the mouse over the horizontal scroll bar and then spin the mouse wheel.