Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. PointHandler types and event handling
Forum Updated to NodeBB v4.3 + New Features

PointHandler types and event handling

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 328 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    werto87
    wrote on last edited by werto87
    #1

    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.14

    Window {
    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

    1 Reply Last reply
    0
    • YunusY Offline
      YunusY Offline
      Yunus
      wrote on last edited by
      #2

      @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")
                  }
              }
              }
              }
          }
      
      1 Reply Last reply
      0
      • W Offline
        W Offline
        werto87
        wrote on last edited by werto87
        #3

        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
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved