PointerDeviceHandler QML Type

Abstract handler for pointer events with device-specific constraints. More...

Properties

Detailed Description

\qmlabstract\since 5.10 \preliminary \inherits PointerHandler \inqmlmodule QtQuick

An intermediate class (not registered as a QML type) for handlers which allow filtering based on device type, pointer type, or keyboard modifiers.

Property Documentation

acceptedButtons : flags

The mouse buttons which can activate this Pointer Handler.

By default, this property is set to Qt.LeftButton. It can be set to an OR combination of mouse buttons, and will ignore events from other buttons.

For example, a control could be made to respond to left and right clicks in different ways, with two handlers:

 Item {
     TapHandler {
         onTapped: console.log("left clicked")
     }
     TapHandler {
         acceptedButtons: Qt.RightButton
         onTapped: console.log("right clicked")
     }
 }

Note: Tapping on a touchscreen or tapping the stylus on a graphics tablet emulates clicking the left mouse button. This behavior can be altered via acceptedDevices or acceptedPointerTypes.


acceptedDevices : flags

The types of pointing devices that can activate this Pointer Handler.

By default, this property is set to PointerDevice.AllDevices. If you set it to an OR combination of device types, it will ignore events from non-matching devices.

For example, a control could be made to respond to mouse and stylus clicks in one way, and touchscreen taps in another way, with two handlers:

 Item {
    TapHandler {
        acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
        onTapped: console.log("clicked")
    }
    TapHandler {
        acceptedDevices: PointerDevice.TouchScreen
        onTapped: console.log("tapped")
    }
 }

acceptedModifiers : flags

If this property is set, it will require the given keyboard modifiers to be pressed in order to react to pointer events, and otherwise ignore them.

If this property is set to Qt.KeyboardModifierMask (the default value), then the PointerHandler ignores the modifier keys.

For example, an Item could have two handlers of the same type, one of which is enabled only if the required keyboard modifiers are pressed:

 Item {
    TapHandler {
        acceptedModifiers: Qt.ControlModifier
        onTapped: console.log("control-tapped")
    }
    TapHandler {
        acceptedModifiers: Qt.NoModifier
        onTapped: console.log("tapped")
    }
 }

If you set acceptedModifiers to an OR combination of modifier keys, it means all of those modifiers must be pressed to activate the handler:

 Item {
    TapHandler {
        acceptedModifiers: Qt.ControlModifier | Qt.AltModifier | Qt.ShiftModifier
        onTapped: console.log("control-alt-shift-tapped")
    }
 }

The available modifiers are as follows:

ConstantDescription
NoModifierNo modifier key is allowed.
ShiftModifierA Shift key on the keyboard must be pressed.
ControlModifierA Ctrl key on the keyboard must be pressed.
AltModifierAn Alt key on the keyboard must be pressed.
MetaModifierA Meta key on the keyboard must be pressed.
KeypadModifierA keypad button must be pressed.
GroupSwitchModifierX11 only (unless activated on Windows by a command line argument). A Mode_switch key on the keyboard must be pressed.
KeyboardModifierMaskThe handler does not care which modifiers are pressed.

If you need even more complex behavior than can be achieved with combinations of multiple handlers with multiple modifier flags, you can check the modifiers in JavaScript code:

 Item {
     TapHandler {
         onTapped:
             switch (point.modifiers) {
             case Qt.ControlModifier | Qt.AltModifier:
                 console.log("CTRL+ALT");
                 break;
             case Qt.ControlModifier | Qt.AltModifier | Qt.MetaModifier:
                 console.log("CTRL+META+ALT");
                 break;
             default:
                 console.log("other modifiers", point.modifiers);
                 break;
             }
     }
 }

See also Qt::KeyboardModifier.


acceptedPointerTypes : flags

The types of pointing instruments (finger, stylus, eraser, etc.) that can activate this Pointer Handler.

By default, this property is set to PointerDevice.AllPointerTypes. If you set it to an OR combination of device types, it will ignore events from non-matching devices.

For example, a control could be made to respond to mouse, touch, and stylus clicks in some way, but delete itself if tapped with an eraser tool on a graphics tablet, with two handlers:

 Rectangle {
    id: rect
    TapHandler {
        acceptedPointerTypes: PointerDevice.Generic | PointerDevice.Finger | PointerDevice.Pen
        onTapped: console.log("clicked")
    }
    TapHandler {
        acceptedPointerTypes: PointerDevice.Eraser
        onTapped: rect.destroy()
    }
 }