Qt Quick Examples - MouseArea | Qt Quick 5.9

Qt 5.9 | Qt Quick | Qt Quick Examples - MouseArea

Qt 5.9.4 Reference Documentation

# Qt Quick Examples - MouseArea

MouseArea example shows how to respond to clicks and drags with a MouseArea. For more information, visit Important Concepts In Qt Quick - User Input.

## Running the Example

To run the example from Qt Creator, open the Welcome mode and select the example from Examples. For more information, visit Building and Running an Example.

## MouseArea Behavior

When you click inside the red square, the Text type will list several properties of that click which are available to QML. The opacity of the red square will be reduced while the mouse is pressed and remains inside the MouseArea.

Signals are emitted by the MouseArea when clicks or other discrete operations occur within it.

      onPressAndHold: btn.text = 'Press and hold'
      onClicked: btn.text = 'Clicked (wasHeld=' + mouse.wasHeld + ')'
      onDoubleClicked: btn.text = 'Double clicked'

MouseArea can also be used to drag items around. By setting the parameters of the drag property, the target item will be dragged around if the user starts to drag within the mouse area boundary.

      drag.target: blueSquare
      drag.axis: Drag.XAndYAxis
      drag.minimumX: 0
      drag.maximumX: box.width - parent.width
      drag.minimumY: 0
      drag.maximumY: box.height - parent.width

Files:

- mousearea/mousearea-wheel-example.qml
- mousearea/mousearea.qml
- mousearea/main.cpp
- mousearea/mousearea.pro
- mousearea/mousearea.qmlproject
- mousearea/mousearea.qrc