MouseArea QML Type

A MouseArea is an invisible item that is typically used in conjunction with a visible item in order to provide mouse handling for that item. By effectively acting as a proxy, the logic for mouse handling can be contained within a MouseArea item.

Example Usage

The following example uses a MouseArea in a Rectangle that changes the Rectangle color to red when clicked:

import QtQuick 2.1

Rectangle {
    width: 100; height: 100
    color: "green"

    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton | Qt.RightButton
        onClicked: {
            if (mouse.button == Qt.RightButton)
                parent.color = 'green';
            else
                parent.color = 'red';
        }
    }
}