Propagate event from a widget to its parent
I've made a ScrollView that contains buttons. I want to be able to scroll it with the mouse wheel.
When the pointer is not on any button it works, but when it is on a button it doesn't. I assume that's because the button receive the mouse wheel event and don't propagate it to the ScrollView.
I've found a workaround to do this. It works but it's very dirty.
button->eventMouseWheel = scroll_view->getClientWidget()->eventMouseWheel;
// Put them all back to NULL before deleting the widgets !!!
Does MyGUI provide a clean way to do this ?
Again an old topic, but I'd need this feature, too. It's also for a very similar setup as the OP has.
Something like an "Ignore mouse wheel" setting for a widget would be nice, to make it "transparent" to mouse wheel changes.
Maybe a "setNeedMouseWheel", in parallel to the already existing "setNeedMouseFocus" function?
Or is there any other, "clean" way to let a widget ignore a mouse wheel event and pass it on to its parent?
Currently there is no clean way to pass mouse wheel to parent.
There are two possible ways to do this.
1. Make widget completely transparent to mouse. Set NeedMouse to false from code or in layout.
2. Assign custom event to widget that calls needed logic from parent or calls parent's eventMouseWheel.
While propagating events to parents whenever they are not handled looks easy it is far from clear how to control this logic:
- you can't simply pass all not handled events to parent, because this might be unwanted;
- adding flag for each even would add way too much garbage to interface and list of widget's properties;
- adding flag for passing/not-passing all event to parent is useless, because you can use NeedMouse/NeedKey flags instead.
I can work on implementation and this feature is quiet useful in many cases, but I need some suggestions how this might work.
I totally agree this would be useful, I have quite a bit of similar workarounds in my code.
As for the implementation I think adding a "NeedMouseWheel" flag analogous to "NeedMouse" might be easiest.
If I'm not mistaken, such a flag as scrawl talked about would also work in cases where the widget below is not the parent, which is another argument for this function.
However, in this case, it might be nice to be able to make it more generic: Be able to pass any widget on. So maybe, something like this might be nice:
widget->setPassOnEvents( MyGUI::Transparency::EVENT_MOUSEWHEEL | MyGUI::Transparency::EVENT_MOUSE_LEFT | MyGUI::Transparency::EVENT_MOUSE_MOVE );
If this is unpractical or too much work, just a setNeedsMouseWheel would be neat.
Thanks again for adding this function. It makes it easy to implement some neat features, like the on-the-fly creation of these screens: