custom widget does not get mousewheel events ?! Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
smf
Knows some wx things
Knows some wx things
Posts: 32
Joined: Wed Nov 12, 2008 7:04 pm

custom widget does not get mousewheel events ?!

Post by smf » Tue Dec 22, 2009 6:56 pm

Hi,

I do not know what I can do any further... I have written some custom widgets. Nearly all of them have OnMouseWheel()-Handlers which are set up in the event-table. Under Linux (GTK) everything works like I expect it to work. That is: if the mouse is over the widget and the mousewheel is turned, a mouse-wheel-event is fired and processed.

Under Win32 (XP/Vista) only the first widget in the sizer-hirarchy gets the mouse-wheel-events while every other widget doesn't react on mouse-wheel-events when the mouse is over the widget...

Any hints of what this could be / what I should check? I tried googl(e)ing and searching this forum but found nothing on that topic, so I guess it's a rather stupid mistake I made...

cu
Stefan

Edit: Even if the mouse is over a completely different widget the first one in the sizer-hirarchy keeps reacting on the mouse-wheel...

tan
Moderator
Moderator
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Re: custom widget does not get mousewheel events ?!

Post by tan » Tue Dec 22, 2009 7:24 pm

smf wrote:Hi,

I do not know what I can do any further... I have written some custom widgets. Nearly all of them have OnMouseWheel()-Handlers which are set up in the event-table. Under Linux (GTK) everything works like I expect it to work. That is: if the mouse is over the widget and the mousewheel is turned, a mouse-wheel-event is fired and processed.

Under Win32 (XP/Vista) only the first widget in the sizer-hirarchy gets the mouse-wheel-events while every other widget doesn't react on mouse-wheel-events when the mouse is over the widget...

Any hints of what this could be / what I should check? I tried googl(e)ing and searching this forum but found nothing on that topic, so I guess it's a rather stupid mistake I made...

cu
Stefan

Edit: Even if the mouse is over a completely different widget the first one in the sizer-hirarchy keeps reacting on the mouse-wheel...
AFAIK under MSW a widget receives MouseWeel events only if this widget has focus (or it has captured mouse input by means of xWindow::CaptureMouse()).
You could intercept wxEVT_ENTER_WINDOW event and set focus to appropriate widget.
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10

smf
Knows some wx things
Knows some wx things
Posts: 32
Joined: Wed Nov 12, 2008 7:04 pm

Re: custom widget does not get mousewheel events ?!

Post by smf » Tue Dec 22, 2009 7:32 pm

tan wrote: AFAIK under MSW a widget receives MouseWeel events only if this widget has focus (or it has captured mouse input by means of xWindow::CaptureMouse()).
You could intercept wxEVT_ENTER_WINDOW event and set focus to appropriate widget.
This sounds like it could be the missing piece ... I'll try it, but I am rather sure even now, that it's the solution for this one.

TIA
Stefan

Edit: Yes, it is the solution :) ... If ever anyone else is getting this trouble: Add this to the event-table:

EVT_ENTER_WINDOW(class::OnEnterWindow)

and add some code like this to the class:

class::OnEnterWindow(wxMouseEvent& WXUNUSED(event))
{
this->SetFocus();
}

Under wxMSW the widget/window-focus does not follow the mouse automagically...

Post Reply