skaldesh
skaldesh

Reputation: 1530

QML `TapHandler`: Find out which Button was pressed in `onSingleTapped`

I have a simple task. I want to find out whether the left or right mouse button was pressed inside TapHandler.onSingleTapped:

TapHandler {
    acceptedButtons: Qt.LeftButton | Qt.RightButton

    onSingleTapped: function(eventPoint) {
        // Print if it was left or right button
    }
}

The supplied eventPoint does not contain this information. Where can I get this info?

Upvotes: 0

Views: 823

Answers (1)

iam_peter
iam_peter

Reputation: 3914

Here you go, taken from TapHandler tapped() documentation:

TapHandler {
    acceptedButtons: Qt.LeftButton | Qt.RightButton

    onSingleTapped: function(eventPoint) {
        console.log("tapped", eventPoint.event.device.name,
                    "button", eventPoint.event.button,
                    "@", eventPoint.scenePosition)
    }
}

But you could also use a dedicated TapHandler for each button type: QtWS17 - Pointer Handlers for fluid applications in Qt Quick

Upvotes: 1

Related Questions