Unsolved PointHandler types and event handling
-
Hi, i want to know how to correctly work with PointHandler types.
In this small example i have 2 pointer Handler and I want to move the blue rectangle only on Long press
How to grab the event? Or how can I trigger a Drag from Qml? What is best practice here?Background: I have a solution in another project where the TapHandler sends a signal to the DragHandler and sets a variable on the DragHandler to true. But this feels kinda bad.
code example:
import QtQuick 2.14
import QtQuick.Window 2.14Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
DragHandler {
id: dragHandler
target: rectangle
}
Rectangle {
id: rectangle
width: 200
height: 200
color: "steelblue"TapHandler { id: tapHandler onTapped: console.log("Tapped") onLongPressed: console.log("LongPressed") } }
}
complete project: https://github.com/werto87/qt_projects branch list_view_model_cxx
-
@werto87 Hi. If you just want to move your rectangle when you pressed longly. You can change DragHandler enable property which is explained here when you are onLongpressed. Here is also code:
import QtQuick 2.11 import QtQuick.Window 2.11 import Qt.labs.handlers 1.0 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Item { anchors.fill: parent DragHandler { id: dragHandler target: rectangle enabled: false } Rectangle { id: rectangle width: 200 height: 200 color: "steelblue" TapHandler { id: tapHandler onTapped: { dragHandler.enabled = false console.log("Tapped") } onLongPressed: { dragHandler.enabled = true console.log("LongPressed") } } } } }
-
Hi Yunus, I am sorry my example was not so good. Your solution is close to the solution i use in my project. For me this feels like a workaround.
My understanding is that there is an EventPoint- EventPoint first gets handled from TapHandler because the button gets pressed
- TapHandler finds out that this event is not a "real" tap event because the user drags after the press event (TapHandler.DragThreshold)
- TapHandler should mark this event as not handled and DragHandler should handle it
Please see this paragraph from TapHandler documentation:
"TapHandler.DragThreshold (the default value) The event point must not move significantly. If the mouse, finger or stylus moves past the system-wide drag threshold (QStyleHints::startDragDistance), the tap gesture is canceled, even if the button or finger is still pressed. This policy can be useful whenever TapHandler needs to cooperate with other input handlers (for example DragHandler) or event-handling Items (for example QtQuick Controls), because in this case TapHandler will not take the exclusive grab, but merely a passive grab."I want to learn
- how to use this "cooperate with other input handlers" works
- what is the passive grab and the active grab
- how to use PointHandler to Handle gestures in my application