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.
Mouse move events will occur only when a mouse button is pressed down, unless mouse tracking has been enabled with setMouseTracking () . Qt automatically grabs the mouse when a mouse button is pressed inside a widget; the widget will continue to receive mouse events until the last mouse button is released.
The QMouseEvent class contains parameters that describe a mouse event. More … Mouse events occur when a mouse button is pressed or released inside a widget, or when the mouse cursor is moved. Mouse move events will occur only when a mouse button is pressed down, unless mouse tracking has been enabled with setMouseTracking () .
If you move the widget as a result of the mouse event, use the global position returned by globalPosition () to avoid a shaking motion. The QWidget::setEnabled () function can be used to enable or disable mouse and keyboard events for a widget.
The button that caused the event is given as a value from the Qt::MouseButton enum. If the event type is MouseMove, the appropriate button for this event is Qt::NoButton. buttons is the state of all buttons at the time of the event, modifiers is the state of all keyboard modifiers.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With