Your code does not work, because at the moment one area of the mouse will be higher than another, mouse events will be occupied only by the area of the mouse that is at the top (until you change the theft property, etc.). Thus, your property of the bottom rectangle, for example, hover, etc., will not work, because all these events will be captured by the top rectangle.
Instead, try the following:
import QtQuick 1.0 Rectangle { id: topParent width: 500 height: 500 color: "grey" Rectangle { id: redRectangle color: "red" width: 80 height: 80 onXChanged: { if( redRectangle.x > greenRectangle.x - redRectangle.width && redRectangle.x < greenRectangle.x + greenRectangle.width && redRectangle.y > greenRectangle.y - redRectangle.height && redRectangle.y < greenRectangle.y + greenRectangle.height ) { console.log ( "Red Over Green" ) } } MouseArea { anchors.fill: parent drag.target: redRectangle drag.axis: Drag.XandYAxis drag.minimumX: 0 drag.maximumX: topParent.width drag.minimumY: 0 drag.maximumY: topParent.height onPressed: redRectangle.z = greenRectangle.z + 1 } } Rectangle { id: greenRectangle color: "green" width: 180 height: 180 onXChanged: { if( greenRectangle.x > redRectangle.x - greenRectangle.width && greenRectangle.x < redRectangle.x + redRectangle.width && greenRectangle.y > redRectangle.y - greenRectangle.height && greenRectangle.y < redRectangle.y + redRectangle.height ) { console.log ( "Green Over Red" ) } } MouseArea { anchors.fill: parent drag.target: greenRectangle drag.axis: Drag.XandYAxis drag.minimumX: 0 drag.maximumX: topParent.width drag.minimumY: 0 drag.maximumY: topParent.height onPressed: greenRectangle.z = redRectangle.z + 1 } } }
Places where I printed messages, you can also generate signals.
source share