How to stack MouseArea objects?
-
MouseAreaseems to be full of perverse design decisions. I have aTabViewand I'd like to enhance it, specifically by making apressAndHoldon a tab close it.If I attach a
MouseAreato theRectangleI use for the tab, and give it anonPressAndHoldhandler, tabs no longer work. The docs suggest that setting thepropagateComposedEventsproperty, and clearingmouse.accepted, might help, but it doesn't. It appears that, while this might do what it literally says, the mere presence ofonPressAndHoldprevents non-composed events, likepressedandreleasedfrom getting through to the underlying tab's built-inMouseArea. How useful.So I thought I might just build my own
pressAndHoldhandler out of aTimerand a pair ofonPressedandonReleasedhandlers, starting the timer in the former and stopping it in the latter, and having theonTriggeredhandler close the tab. Not surprisingly, this prevents the tabs from working, because thepressedsignal is swallowed by my own handler. So I clearmouse.acceptedin my handler, which makes tabs work again. But now myonReleasedhandler never gets called, because theMouseArealogic assumes that if I clearedmouse.acceptedin myonPressedhandler, it must mean that I ignored the press, and couldn't possibly have any interest in the release. Brilliant design choice.So what do I do? At every step of the way,
MouseAreais fighting against me. How do I add processing to mouse events without interfering with other objects that want to listen to the same events?