简体   繁体   中英

Qt MouseMoveEvent only triggers with a mouse button press

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM