Why not use a MouseArea or the new HoverHandler. Anyway, fill the root item 
with a mouseare or you can use the Item function:
https://doc.qt.io/qt-5/qml-qtquick-item.html#mapToGlobal-method
to convert local mouse coordinate to global coordintate (reverse from is also 
available).

You can wrap this into a component that you instanciate into you root item, 
this will act like a optional addon and no need to subclass.


[36E56279]
une compagnie  [cid:image002.jpg@01D4DFCD.9DD2E1C0]
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@01D4DFCD.9DD2E1C0]<https://www.facebook.com/LesSolutionsAmotus/>
 [cid:image004.png@01D4DFCD.9DD2E1C0] 
<https://www.linkedin.com/company/amotus-solutions/>  
[cid:image005.png@01D4DFCD.9DD2E1C0] <https://twitter.com/AmotusSolutions>  
[cid:image006.jpg@01D4DFCD.9DD2E1C0] 
<https://www.youtube.com/channel/UCoYpQgsmj1iJZyDjTQ3x8Ig>





From: Interest <interest-boun...@qt-project.org> On Behalf Of René Hansen
Sent: March 21, 2019 9:36 AM
To: interest <interest@qt-project.org>
Subject: Re: [Interest] Track global mouse position in QML

For now I'm doing this:

class MouseTrackableWindow : public QQuickWindow
{
  Q_OBJECT
public:
  void mouseMoveEvent(QMouseEvent *event) override {
    QQuickWindow::mouseMoveEvent(event);
    emit mouseMove(event->windowPos());
  }

signals:
  void mouseMove(QPointF mouse);
};

...

qmlRegisterType<MouseTrackableWindow>("foo.components", 1, 0, 
"MouseTrackableWindow");

...
import QtQuick 2.12

import foo.components 1.0

MouseTrackableWindow {
  title: qsTr("Hello World")

  onMouseMove: {
    console.log(mouse.x, mouse.y);
  }
}

And it's not all too bad, but if anyone can tell me of a more dogmatic QtQuick 
based approach, please let me know.

I'm not sure missing whatever is left in 
QQuickWindowQmlImpl<https://github.com/qt/qtdeclarative/blob/5.12/src/quick/items/qquickwindowmodule_p.h>
 is going to wind up giving me problems later. Subclassing that means including 
private headers etc. so I'm not to keen on going that route.


/René

On Thu, 21 Mar 2019 at 12:50 René Hansen 
<ren...@gmail.com<mailto:ren...@gmail.com>> wrote:
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@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to