16

I have an odd problem here.

I'm working on an application, and within one of my classes I'm monitoring my mouse events.

The weird thing is, my mouse move event will only get called if any mouse button is pressed.

I'm not even filtering for any button presses within the method; the method itself doesn't even get called unless I click on this object itself (the one that's monitoring it).

What generally causes this type of error to happen?

I'm not sure if it's relevant, but I have 2 different things monitoring my mouse inputs: 1) the main program monitoring the global mouse coordinates, and 2) an object within my program monitoring the mouse coordinates within itself.

Edit So the problem has to be because mouse move event is generally used when people are dragging the cursor along the screen right? My reason for not needing it like that is because I'm building a custom context menu of sorts, and I need to know when an item is hovered over.

Yattabyte
  • 1,280
  • 14
  • 28

1 Answers1

24

It turns out that I didn't truly set everything within my class to enable mouse tracking. I somehow thought if the class itself was set to have it enabled, I wouldn't need to set it to all the sub objects, but now I see how that wouldn't make any sense at all.

So just to clarify my solution: The items that I needed to track my cursor's position needed to have

setMouseTracking(true);
Yattabyte
  • 1,280
  • 14
  • 28
  • 1
    Also note that if you are calling `setViewport()`, you have to do it before calling `setMouseTracking()`, otherwise tracking will not work. – Nikola Malešević Jul 29 '17 at 15:24