On Fri, Mar 5, 2021 at 11:40 AM Mitch Curtis <mitch.cur...@qt.io> wrote:
> > -----Original Message----- > > From: Interest <interest-boun...@qt-project.org> On Behalf Of Mark > Gaiser > > Sent: Friday, 5 March 2021 10:39 AM > > To: Qt Interest <interest@qt-project.org> > > Subject: [Interest] Does QML have a way to detect if a click is outside > an > > element? > > > > 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? > > Popup provides this functionality: > > https://doc.qt.io/qt-5/qml-qtquick-controls2-popup.html > > Hi Mitch, Thank you! That actually worked! :) I'm surprised because the code where i used this uses QtQuick.Controls 1 and 2, which smells scary. But hey, it works.
_______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest