Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 269
Yattabyte Avatar asked Aug 10 '14 00:08

Yattabyte


People also ask

How do I get a mouse move event in Qt?

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.

What is qmouseevent in QForms?

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 () .

How to disable mouse and keyboard events for a qwidget?

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.

How to get the button that caused an event in Qt?

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.


1 Answers

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);
like image 161
Yattabyte Avatar answered Sep 20 '22 14:09

Yattabyte