How to block background click when clicked on the item placed above ?
-
Hi,
I came across a scenario where I have a rectangle place on top of another rectangle. But when I click on top rectangle ,it is taking below rectangle's click as in below rectangle's mouse area onClicked handler is getting called.Can anyone please suggest me better approach to handle the mouse click separately for both rectangles ?
-
In your top MouseArea, how do you intercept the clicks? Also using
onClicked
? In general, take a look at this property, it controls exactly the behaviour you are describing: https://doc.qt.io/qt-6/qml-qtquick-mousearea.html#propagateComposedEvents-prop@sierdzio If suppose I do not have any mouse area on top rectangle, then the below mouse area is getting called !
If I have mouse area on top rectangle, then below rectangle's click is not happening, but is there any other better approach other than blocking background click using mouse area ??
-
Hi,
I came across a scenario where I have a rectangle place on top of another rectangle. But when I click on top rectangle ,it is taking below rectangle's click as in below rectangle's mouse area onClicked handler is getting called.Can anyone please suggest me better approach to handle the mouse click separately for both rectangles ?
In your top MouseArea, how do you intercept the clicks? Also using
onClicked
? In general, take a look at this property, it controls exactly the behaviour you are describing: https://doc.qt.io/qt-6/qml-qtquick-mousearea.html#propagateComposedEvents-prop -
In your top MouseArea, how do you intercept the clicks? Also using
onClicked
? In general, take a look at this property, it controls exactly the behaviour you are describing: https://doc.qt.io/qt-6/qml-qtquick-mousearea.html#propagateComposedEvents-prop@sierdzio If suppose I do not have any mouse area on top rectangle, then the below mouse area is getting called !
If I have mouse area on top rectangle, then below rectangle's click is not happening, but is there any other better approach other than blocking background click using mouse area ??
-
@sierdzio If suppose I do not have any mouse area on top rectangle, then the below mouse area is getting called !
If I have mouse area on top rectangle, then below rectangle's click is not happening, but is there any other better approach other than blocking background click using mouse area ??
@MayankJha said in How to block background click when clicked on the item placed above ?:
@sierdzio If suppose I do not have any mouse area on top rectangle, then the below mouse area is getting called !
Ah then this is 100% correct behaviour. By default, all QML components are transparent to mouse clicks.
If I have mouse area on top rectangle, then below rectangle's click is not happening, but is there any other better approach other than blocking background click using mouse area ??
Best is to use a
MouseArea
, yes. -
@MayankJha said in How to block background click when clicked on the item placed above ?:
@sierdzio If suppose I do not have any mouse area on top rectangle, then the below mouse area is getting called !
Ah then this is 100% correct behaviour. By default, all QML components are transparent to mouse clicks.
If I have mouse area on top rectangle, then below rectangle's click is not happening, but is there any other better approach other than blocking background click using mouse area ??
Best is to use a
MouseArea
, yes. -