Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.12.3
-
None
-
-
8068e7b98cde09565efe27585b84e120f9c5ea99 (qt/qtdeclarative/dev)
Description
Example:
QML:
import QtQuick 2.12 import QtQuick.Window 2.12 Window { width: 500 height: 500 visible: true Rectangle { x: 0 y: 0 width: 5 height: 20 visible: true MouseArea { drag.target: parent drag.axis: Drag.XAxis drag.minimumX: 0 drag.maximumX: 250 drag.threshold: 0 drag.smoothed: false onMouseXChanged: { console.log("Rect X: " + parent.x); console.log("Mouse X (relative to Rectangle): " + mouseX); console.log("Mouse X (relative to Window): " + (parent.x + mouseX)); } } } }
The following output appears when moving the mouse from 0 to 250:
QDEBUG : Drag::Test_SlideFromLeftToRight() qml: Mouse X (relative to Rectangle): 4 QDEBUG : Drag::Test_SlideFromLeftToRight() qml: Mouse X (relative to Window): 247 QDEBUG : Drag::Test_SlideFromLeftToRight() qml: Rect X: 247 QDEBUG : Drag::Test_SlideFromLeftToRight() qml: Mouse X (relative to Rectangle): 4 QDEBUG : Drag::Test_SlideFromLeftToRight() qml: Mouse X (relative to Window): 251 QDEBUG : Drag::Test_SlideFromLeftToRight() qml: Rect X: 250 QDEBUG : Drag::Test_SlideFromLeftToRight() qml: Mouse X (relative to Rectangle): 3 QDEBUG : Drag::Test_SlideFromLeftToRight() qml: Mouse X (relative to Window): 253
Description
In short: The relative mousecoordinate is wrong when you drag an item (in this example an Rectangle) via an embedded MouseArea. Mouse X (relative to Window) should never be greater 250, but in this example it is (251, 253)! The mouse has always an offset.
Condition: MouseArea global position must depend on position of the dragged item (in this example MouseArea is parent of Rectangle).
The Problem: The rectangle is moved to the new coordinates but the relative mousecoordinates are NOT "corrected".
Analysis: qquickmousearea.cpp
void QQuickMouseArea::mouseMoveEvent(QMouseEvent *event)
If dragged item has impact on global position of MouseArea the mousecoordinate should be "corrected"
A demo is attached.
Workarround
For users with the same issue:
MouseArea { property var oldX : 0; drag.target: parent drag.axis: Drag.XAxis drag.minimumX: 0 drag.maximumX: 250 drag.threshold: 0 drag.smoothed: false onMouseXChanged: { console.log("Rect X: " + parent.x); console.log("Mouse X (relative to Rectangle): " + mouseX); console.log("Mouse X (relative to Window): " + (parent.x + mouseX)); console.log("Mouse X (relative to Window correct): " + (parent.x + mouseX - (parent.x - oldX))); oldX = parent.x } }
Attachments
Issue Links
- resulted in
-
QTBUG-85111 MouseX in Mouse area reports different value with Qt 5.15.0 and Qt 5.12.4 on dragging
-
- Closed
-