MouseEvent Element Reference

The MouseEvent object provides information about a mouse event.

This element was introduced in Qt 4.7.

Detailed Description

The MouseEvent object provides information about a mouse event.

The position of the mouse can be found via the x and y properties. The button that caused the event is available via the button property.

Properties

Property Documentation

Setting accepted to true prevents the mouse event from being propagated to items below this item.

Generally, if the item acts on the mouse event then it should be accepted so that items lower in the stacking order do not also respond to the same event.

This property holds the button that caused the event. It can be one of:

  • Qt.LeftButton
  • Qt.RightButton
  • Qt.MiddleButton
  • buttons : int

This property holds the mouse buttons pressed when the event was generated. For mouse move events, this is all buttons that are pressed down. For mouse press and double click events this includes the button that caused the event. For mouse release events this excludes the button that caused the event.

It contains a bitwise combination of:

  • Qt.LeftButton
  • Qt.RightButton
  • Qt.MiddleButton
  • modifiers : int

This property holds the keyboard modifier flags that existed immediately before the event occurred.

It contains a bitwise combination of:

  • Qt.NoModifier - No modifier key is pressed.
  • Qt.ShiftModifier - A Shift key on the keyboard is pressed.
  • Qt.ControlModifier - A Ctrl key on the keyboard is pressed.
  • Qt.AltModifier - An Alt key on the keyboard is pressed.
  • Qt.MetaModifier - A Meta key on the keyboard is pressed.
  • Qt.KeypadModifier - A keypad button is pressed.

For example, to react to a Shift key + Left mouse button click:

  1.                 MouseArea  {
  2.     onClicked:  {
  3.         if ((mouse.button == Qt.LeftButton) && (mouse.modifiers & Qt.ShiftModifier))
  4.             doSomething();
  5.     }
  6. }

This property is true if the mouse button has been held pressed longer the threshold (800ms).

These properties hold the coordinates of the position supplied by the mouse event.

Notes provided by the Qt Community
Informative
  • 5

Votes: 1

Coverage: Qt library 4.8, 4.7

Picture of Vladimir Vladimir

Ant Farmer
1 note

This person works for Qt Development Frameworks.

Using MouseEvent in own signals

If you have an own signal which processes mouse events from a MouseArea, you have use variant as type in the definition of that signal:

  1. signal clicked(variant mouse)

This one does not parse:

  1. signal clicked(MouseEvent mouse)

mouse will still be converted to MouseEvent when it arrived at the recipient side.

[Revisions]