[Interest] Track global mouse position in QML

Jérôme Godbout godboutj at amotus.ca
Thu Mar 21 15:35:47 CET 2019


Not sure I get what you are trying to achieve, but having a mouse area where the coordinate are local you can map them to global or to an item. If the mouse area should not grab the mouse event, make sure to add those to your mouse area

hoverEnabled: true
preventStealing: true
propagateComposedEvents: true
acceptedButtons: Qt.NoButton

Also do not accept the events if not processing it or the event will be stopped (do this for all event that can be accepted):

onClicked:
{
   mouse.accepted = false;
}

This should make your overlay mouse area nearly transparent. This way the mouseArea overlay known the “global position” and can act upon it and the actual behavior under it can process the click like normal.

You can use a single mouse area that overlay the whole items tree (MouseArea into Root Item fill) and change the global coordinate into a Qml Singleton. Any part of the application could connect to the coordinate and check if the global to whatever item you need match and act according to it.


[36E56279]
une compagnie  [cid:image002.jpg at 01D4DFD1.D847A580]
RAPPROCHEZ LA DISTANCE

Jérôme Godbout
Développeur Logiciel Sénior /
Senior Software Developer

p: +1 (418) 800-1073 ext.:109

amotus.ca<http://www.amotus-solutions.com/>
statum-iot.com<http://statum-iot.com/>
[cid:image003.png at 01D4DFD1.D847A580]<https://www.facebook.com/LesSolutionsAmotus/> [cid:image004.png at 01D4DFD1.D847A580] <https://www.linkedin.com/company/amotus-solutions/>  [cid:image005.png at 01D4DFD1.D847A580] <https://twitter.com/AmotusSolutions>  [cid:image006.jpg at 01D4DFD1.D847A580] <https://www.youtube.com/channel/UCoYpQgsmj1iJZyDjTQ3x8Ig>





From: Interest <interest-bounces at qt-project.org> On Behalf Of Jason H
Sent: March 21, 2019 10:11 AM
To: "René Hansen" <renehh at gmail.com>
Cc: interest <interest at qt-project.org>
Subject: Re: [Interest] Track global mouse position in QML

Please forgive me if I don't completely understand...

Maybe you want an underlying mouse area, not an overlaynig one? I'd suggest you just move the MouseArea in the file.
You can always use an overlaying one and translate the mouse events to the child, if there is one. This is what I do for a sample drawing app I have:

In TouchTestRect.qml:



function dispatchTouchEvent(x,y) {

var c = childAt(x,y);

var typename =  "" + c;

var box;

if (c && (typename.startsWith("QQuickRow") || typename.startsWith("QQuickColumn"))) {

        var point = mapToItem(c, x, y);

        box = c.childAt(point.x, point.y);

        typename =  "" + box;

} else if(typename.startsWith("TouchHitBox_QMLTYPE")) {
....

}
...
}

then:
MouseArea {
anchors.fill: parent
onMouseXChanged: {
touchTestRect.dispatchTouchEvent(mouseX, mouseY)
}
onMouseYChanged: {
touchTestRect.dispatchTouchEvent(mouseX, mouseY)
}
}
Sent: Thursday, March 21, 2019 at 7:50 AM
From: "René Hansen" <renehh at gmail.com<mailto:renehh at gmail.com>>
To: interest <interest at qt-project.org<mailto:interest at qt-project.org>>
Subject: [Interest] Track global mouse position in QML
Hi all,


I want to track mouse movement within my entire application window, because I need to show/hide/move items around where my cursor is at certain times. (Think e.g. custom cursor)

I can do it easily by filling the entire window with a MouseArea and handle onPositionChanged. The problem is that any mouse sensitive inputs underneath, then get's blocked by the overlaying MouseArea. E.g. a TextField that is usually highlighted on hover and clickable, no longer receives any mouse events.

Is there any straightforward solution to this?

I know QQuickWindow has a mouseMoveEvent, but that doesn't seem to be exposed in QML and if I can avoid subclassing and exposing a custom class, I'd rather do that.


Cheers,

René Hansen
_______________________________________________ Interest mailing list Interest at qt-project.org<mailto:Interest at qt-project.org> https://lists.qt-project.org/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190321/d70d36fd/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 6751 bytes
Desc: image001.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190321/d70d36fd/attachment-0003.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.jpg
Type: image/jpeg
Size: 1016 bytes
Desc: image002.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190321/d70d36fd/attachment-0004.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 483 bytes
Desc: image003.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190321/d70d36fd/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 506 bytes
Desc: image004.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190321/d70d36fd/attachment-0004.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.png
Type: image/png
Size: 500 bytes
Desc: image005.png
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190321/d70d36fd/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image006.jpg
Type: image/jpeg
Size: 713 bytes
Desc: image006.jpg
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190321/d70d36fd/attachment-0005.jpg>


More information about the Interest mailing list