Search code examples
c++qtmousetrackingqwidget

Qt mouseMoveEvent - tracking mouse position


I'm programming my first 2D game in Qt.

I have QWidged where I draw my game (isometric view). When mouse enters border of widget it moves map view (like in every strategy game...).

And here is my trouble... I'm tracking mouse position with mouseMoveEvent but it fires only when mouse moves (only when position changes). So map moves only when I move mouse at borders. If mouse stand still, map does not move (mouseMoveEvent is not triggered). And I have no idea how to solve this. It's annoying when you try to play it.

This is my first post here.. and I hope that I explained my problem clearly :)

Edit (little more clarify):
Imagine this: you want to move map. So you move mouse to the edge of screen (QWidget) but at the moment when you stop mouse, map stops moving too. But mouse is still at edge of screen. What I want to do is that map will still move after mouse stops at edge.


Solution

  • You can create QPropertyAnimation for coordinates and start/stop it when mouse moves to/from widget's border. Or you can remember current state ("changing x by -1 every 100ms, changing y by 0") and call some slot that does the real moving with QTimer.