[Interest] Does QML have a way to detect if a click is outside an element?

Mark Gaiser markg85 at gmail.com
Fri Mar 5 10:39:21 CET 2021


Hi,

Picture a QML window with a red rectangle in the middle of it (say 200x200
px).
The window itself is, say, 500x500 px.

Now I'm looking for a way to detect when you click on any area outside the
red rectangle but inside the white window area.

The reason I need this is to provide a more intuitive interaction. In my
particular case the red rectangle is a calendar popup that needs to go away
when you click outside of it but inside the window still.

I can imagine 2 possible solutions, both are quite cumbersome to implement.

1. One can make a kind of "EventFilter" object in C++ and expose it to QML.
So that custom event filters can be made which would allow me to find a
click that occurs outside the rectangle.

2. I can make an application with overlapping MouseArea{} and figure it out
that way. But this is really hacky and very error prone.

Does QML provide another more native way for this kind of interaction?

Best regards,
Mark Gaiser
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210305/addc6a76/attachment.html>


More information about the Interest mailing list