'QML/MouseArea: onEntered not triggered when mouse pressed on another mouse area
I need to detect a selection range with MouseAreas. So I want to detect a mousePressed on any object, before the release I need to detect onEntered on any other object and then mouseRelease on anyObject I'm focusing on detecting enter events on an item after pressing on another item. A simplification of my objects:
import QtQuick 2.15
Rectangle {
property color color: "red"
property string name: "rect1"
property Item mousePressedObserver
width: 100
height: 20
border.color: ma.visible ? color: "grey"
border.width: 1
MouseArea {
id: ma
acceptedButtons: Qt.LeftButton
anchors.fill: parent
hoverEnabled: true
preventStealing: false
propagateComposedEvents: true
drag.target: undefined
onPressed: {
if(mousePressedObserver) mousePressedObserver.onPressed()
mouse.accepted = true
}
onPositionChanged: mouse.accepted = true
onReleased: if(mousePressedObserver) mousePressedObserver.onReleased()
onEntered: {border.width= 2; console.log(name + " entered")}
onExited: {border.width= 1; console.log(name + " exited"); hoverEnabled= false}
onContainsMouseChanged: console.log(name + " containsMouse: " + containsMouse)
}
}
A simplification of my view:
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Layouts 1.15
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
MouseArea {
acceptedButtons: Qt.LeftButton
anchors.fill: parent
hoverEnabled: true
onPressed: indicator.onPressed()
onReleased: indicator.onReleased()
ColumnLayout {
CustomRect {mousePressedObserver: indicator}
CustomRect { name: "rect2"; color: "blue"; mousePressedObserver: indicator}
CustomRect { name: "rect3"; color: "green"; mousePressedObserver: indicator}
MouseStatusIndicator { id: indicator}
}
}
}
If I press on the first rect, and without releasing, mouve to the second rect, the onEntered handler is called only after releasing the mouse. If i don't press the mouse, enter is detected "real-time". Is it possible to detect the enter event even if mousse is pressed?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
