|  | Home · Overviews · Examples |

# QMouseEvent Class Reference
[com.trolltech.qt.gui module]

The `QMouseEvent` class contains parameters that describe a mouse event. More...

Inherits `QInputEvent`.

## Detailed Description

The `QMouseEvent` class contains parameters that describe a mouse event.

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 QWidget::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.

A mouse event contains a special accept flag that indicates whether the receiver wants the event. You should call `ignore` if the mouse event is not handled by your widget. A mouse event is propagated up the parent widget chain until a widget accepts it with `accept`, or an event filter consumes it.

The state of the keyboard modifier keys can be found by calling the modifiers() function, inhertied from `QInputEvent`.

The functions `pos`, `x`, and `y` give the cursor position relative to the widget that receives the mouse event. If you move the widget as a result of the mouse event, use the global position returned by `globalPos` to avoid a shaking motion.

The QWidget::setEnabled() function can be used to enable or disable mouse and keyboard events for a widget.

Reimplement the `QWidget` event handlers, QWidget::mousePressEvent(), QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(), and QWidget::mouseMoveEvent() to receive mouse events in your own widgets.

QCursor::pos()

See also `QWidget::setMouseTracking` and `QWidget::grabMouse`.