QML (Qt6.4) MouseArea not detecting 'containsPress' from another MouseArea
-
Hi Qt community !
I was trying to catch a
containsPressin myMouseArea, and I found out that, if you have twoMouseArea'sand you press on one of them when move your mouse to anotherMouseAreawhile holding left button down so the secondMouseAreashould (I assume) detectcontainsPressbecause I still holding button, but is not detecting that.
I tried to UseHoverHandlerinstead and usedpoint.pressedButtonsto see if button is pressed in the area does not work for me ether.
Is this a bug or normal behavior ?I will appreciate any suggestions on how to catch a mouse press in MouseArea which was pressed and transferred from another MouseArea.
Thank you very much!This is a minimum reproduction code:
import QtQuick import QtQuick.Layouts Window { width: 800 height: 480 visible: true title: qsTr("Hello World") RowLayout { Rectangle { width: 300 height: 300 color: firstMouseArea.pressed ? "lightpink" : "lightgray" border.width: 2 border.color: "blue" // Debug info ColumnLayout { Text { text: "Contains Mouse: " + firstMouseArea.containsMouse } Text { text: "Contains Press: " + firstMouseArea.containsPress + " with button: " + firstMouseArea.pressedButtons } Text { text: " Pressed: " + firstMouseArea.pressed + " with button: " + firstMouseArea.pressedButtons } } MouseArea { id: firstMouseArea anchors.fill: parent hoverEnabled: true } } Rectangle { width: 300 height: 300 color: secondMouseArea.pressed ? "lightpink" : "lightgray" border.width: 2 border.color: "blue" // Debug info ColumnLayout { Text { text:"Contains Mouse: " + secondMouseArea.containsMouse } Text { text: "Contains Press: " + secondMouseArea.containsPress + " , with button: " + secondMouseArea.pressedButtons } Text { text: " Pressed " + secondMouseArea.pressed + " , with button: " + secondMouseArea.pressedButtons } } MouseArea { id: secondMouseArea hoverEnabled: true anchors.fill: parent } } } } -
Hi Qt community !
I was trying to catch a
containsPressin myMouseArea, and I found out that, if you have twoMouseArea'sand you press on one of them when move your mouse to anotherMouseAreawhile holding left button down so the secondMouseAreashould (I assume) detectcontainsPressbecause I still holding button, but is not detecting that.
I tried to UseHoverHandlerinstead and usedpoint.pressedButtonsto see if button is pressed in the area does not work for me ether.
Is this a bug or normal behavior ?I will appreciate any suggestions on how to catch a mouse press in MouseArea which was pressed and transferred from another MouseArea.
Thank you very much!This is a minimum reproduction code:
import QtQuick import QtQuick.Layouts Window { width: 800 height: 480 visible: true title: qsTr("Hello World") RowLayout { Rectangle { width: 300 height: 300 color: firstMouseArea.pressed ? "lightpink" : "lightgray" border.width: 2 border.color: "blue" // Debug info ColumnLayout { Text { text: "Contains Mouse: " + firstMouseArea.containsMouse } Text { text: "Contains Press: " + firstMouseArea.containsPress + " with button: " + firstMouseArea.pressedButtons } Text { text: " Pressed: " + firstMouseArea.pressed + " with button: " + firstMouseArea.pressedButtons } } MouseArea { id: firstMouseArea anchors.fill: parent hoverEnabled: true } } Rectangle { width: 300 height: 300 color: secondMouseArea.pressed ? "lightpink" : "lightgray" border.width: 2 border.color: "blue" // Debug info ColumnLayout { Text { text:"Contains Mouse: " + secondMouseArea.containsMouse } Text { text: "Contains Press: " + secondMouseArea.containsPress + " , with button: " + secondMouseArea.pressedButtons } Text { text: " Pressed " + secondMouseArea.pressed + " , with button: " + secondMouseArea.pressedButtons } } MouseArea { id: secondMouseArea hoverEnabled: true anchors.fill: parent } } } }@Siarhei-Darhel said in QML (Qt6.4) MouseArea not detecting 'containsPress' from another MouseArea:
Is this a bug or normal behavior ?
I think it's normal. That's how buttons behave on all operating systems (the original button remains pressed even if you move the mouse cursor out of it).
To get what you expect I can think of 2 solutions:
- reimplement
onPressedand make sure to not accept the eventmouse.accepted = false - use drag & drop https://doc.qt.io/qt-6/qtquick-draganddrop-example.html
- reimplement
-
@Siarhei-Darhel said in QML (Qt6.4) MouseArea not detecting 'containsPress' from another MouseArea:
Is this a bug or normal behavior ?
I think it's normal. That's how buttons behave on all operating systems (the original button remains pressed even if you move the mouse cursor out of it).
To get what you expect I can think of 2 solutions:
- reimplement
onPressedand make sure to not accept the eventmouse.accepted = false - use drag & drop https://doc.qt.io/qt-6/qtquick-draganddrop-example.html
@sierdzio Thank you very much for reply !
I will try ! - reimplement