QML pointer handlers and handling grab changes

Viewed 270

In Qt 5.10 Pointer Handlers were introduced. I'm trying to use these instead of MouseArea in my application. In particular, I am using DragHandler. I would like to determine when a drag has started and be notified of grab changes. Qt provides DragHandler::grabChanged(GrabTransition transition, EventPoint point) (see here) so in my code I am using this as:

DragHandler{
    id: dragHandler
    onGrabChanged: {
    // how to use transition ???
    }
}

However, the GrabTransition seems not to be implemented and the documentation doesn't give any clue on what values this enum can take.

2 Answers

It's surprising that the documentation doesn't really explain this. From the source code, I was able to determine the code below. The comments come straight from the source code:

DragHandler {
    onGrabChanged: {
        switch (transition) {
        case EventPoint.GrabPassive:
        case EventPoint.GrabExclusive:
            break;
        case EventPoint.UngrabPassive:
        case EventPoint.UngrabExclusive:
            break;
        case EventPoint.CancelGrabPassive:
        case EventPoint.CancelGrabExclusive:
             // the grab was stolen by something else
            break;
        case EventPoint.OverrideGrabPassive:
            // Passive grab is still there, but we won't receive point updates right now.
            // No need to notify about this.
            break;
        }
    }
}

For QT 6.2 GrabTransition enum located in PointerDevice

 enum GrabTransition {
    GrabPassive = 0x01,
    UngrabPassive = 0x02,
    CancelGrabPassive = 0x03,
    OverrideGrabPassive = 0x04,
    GrabExclusive = 0x10,
    UngrabExclusive = 0x20,
    CancelGrabExclusive = 0x30,
};

So it would be e.g PointerDevice.GrabPassive

Related