Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to track `onDragStarted` and `onDragFinished` on a Drag QML component added to a MouseArea

How to track `onDragStarted` and `onDragFinished` on a Drag QML component added to a MouseArea

Scheduled Pinned Locked Moved Solved Mobile and Embedded
7 Posts 4 Posters 4.2k 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.
  • Roby BrundleR Offline
    Roby BrundleR Offline
    Roby Brundle
    wrote on last edited by
    #1

    I have MouseArea with a Drag QML component to start with. I want to track the drag start and end events when user tries to panMyQmlComponent

    Code:

    import QtQuick 2.7
    
    MyQmlComponent {
        id: myqmlcomponent
    
        MouseArea {
            anchors.fill: parent
            drag.target: myqmlcomponent
    
            drag {
                axis: Drag.XandYAxis
    
                onActiveChanged: {
                    console.log("onActiveChanged called")
                }
    
                onDragStarted: {
                    console.log("onDragStarted called")
                }
    
                onDragFinished: {
                    console.log("onDragFinished called")
                }
            }
        }
    }
    

    Problem:
    onActiveChanged works fine. It is called I start to drag myqmlcomponent and also when I stop dragging. But adding onDragStarted and onDragFinished causes my application to crash on start up complaining the following

    Cannot assign to non-existent property "onDragFinished"
    

    Same with onDragStarted.

    Cannot assign to non-existent property "onDragStarted"
    

    Question:
    What am I missing here? What should I do more to be able to track onDragStarted and onDragFinished?

    raven-worxR 1 Reply Last reply
    0
    • Roby BrundleR Roby Brundle

      I have MouseArea with a Drag QML component to start with. I want to track the drag start and end events when user tries to panMyQmlComponent

      Code:

      import QtQuick 2.7
      
      MyQmlComponent {
          id: myqmlcomponent
      
          MouseArea {
              anchors.fill: parent
              drag.target: myqmlcomponent
      
              drag {
                  axis: Drag.XandYAxis
      
                  onActiveChanged: {
                      console.log("onActiveChanged called")
                  }
      
                  onDragStarted: {
                      console.log("onDragStarted called")
                  }
      
                  onDragFinished: {
                      console.log("onDragFinished called")
                  }
              }
          }
      }
      

      Problem:
      onActiveChanged works fine. It is called I start to drag myqmlcomponent and also when I stop dragging. But adding onDragStarted and onDragFinished causes my application to crash on start up complaining the following

      Cannot assign to non-existent property "onDragFinished"
      

      Same with onDragStarted.

      Cannot assign to non-existent property "onDragStarted"
      

      Question:
      What am I missing here? What should I do more to be able to track onDragStarted and onDragFinished?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Roby-Brundle said in How to track `onDragStarted` and `onDragFinished` on a Drag QML component added to a MouseArea:

      What am I missing here? What should I do more to be able to track onDragStarted and onDragFinished?

      Thats because there are no such methods neither signals you are looking for.
      Whats wrong with the active property?! it's set to true when the drag started, false when it's finished.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      Roby BrundleR 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @Roby-Brundle said in How to track `onDragStarted` and `onDragFinished` on a Drag QML component added to a MouseArea:

        What am I missing here? What should I do more to be able to track onDragStarted and onDragFinished?

        Thats because there are no such methods neither signals you are looking for.
        Whats wrong with the active property?! it's set to true when the drag started, false when it's finished.

        Roby BrundleR Offline
        Roby BrundleR Offline
        Roby Brundle
        wrote on last edited by Roby Brundle
        #3

        @raven-worx ah.. there are no such signals? May be I misread this documentation on Drag

        how do I know when active is false or true when onActiveChanged is called? What is the "syntax" or "way" to track active true or false?

        Doing the following never gets me a call where active is false. Is this correct or am I still expecting something wrong ?

        onActiveChanged: {
            if (active) {
                console.log("Drag is Active")
            }
            else {
                console.log("Drag is InActive")
            }
        }
        
        raven-worxR 1 Reply Last reply
        0
        • Roby BrundleR Roby Brundle

          @raven-worx ah.. there are no such signals? May be I misread this documentation on Drag

          how do I know when active is false or true when onActiveChanged is called? What is the "syntax" or "way" to track active true or false?

          Doing the following never gets me a call where active is false. Is this correct or am I still expecting something wrong ?

          onActiveChanged: {
              if (active) {
                  console.log("Drag is Active")
              }
              else {
                  console.log("Drag is InActive")
              }
          }
          
          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @Roby-Brundle said in How to track `onDragStarted` and `onDragFinished` on a Drag QML component added to a MouseArea:

          ah.. there are no such signals? May be I misread this documentation on Drag

          Thats the wrong doc ;) you need to see the drag (grouped) property from MouseArea element.

          Strange, that should get false. Otherwise how would you get notified again when it changes back to true again :)

          But try to adress it directly: mouseAreaId.drag.active

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          Roby BrundleR 1 Reply Last reply
          2
          • raven-worxR raven-worx

            @Roby-Brundle said in How to track `onDragStarted` and `onDragFinished` on a Drag QML component added to a MouseArea:

            ah.. there are no such signals? May be I misread this documentation on Drag

            Thats the wrong doc ;) you need to see the drag (grouped) property from MouseArea element.

            Strange, that should get false. Otherwise how would you get notified again when it changes back to true again :)

            But try to adress it directly: mouseAreaId.drag.active

            Roby BrundleR Offline
            Roby BrundleR Offline
            Roby Brundle
            wrote on last edited by
            #5

            @raven-worx MouseAreaID.drag.active gives me the correct state that I want to check.
            Marked this topic as solved. Thanks a lot !

            1 Reply Last reply
            0
            • Aleksey_KA Offline
              Aleksey_KA Offline
              Aleksey_K
              wrote on last edited by
              #6

              I solved this issue by adding explicit dragActive property to the MouseArea. Sample code:

              MouseArea {
                  id: mouseArea
                  drag {
                      target: myItem
                      axis: Drag.YAxis
                  }
                  
                  property bool dragActive: drag.active
                  
                  onDragActiveChanged: {
                      if(drag.active) { //
                          ... // Dragging started
                      } else {
                          ... // Dragging finished
                      }
                  }
              }
              
              1 Reply Last reply
              1
              • M Offline
                M Offline
                Mairtin
                wrote on last edited by
                #7

                Came across this issue, so I guess it's still relative as of 6.5.1

                1. onDragStarted and onDragFinished are both still "nonexistent" properties of Drag, despite autocompleteing in the editor.

                2. @Aleksey_K The addition of the property is not necessary. @Roby-Brundle's second code was very close:

                drag { // Not mentioned, but presumedly inside drag.
                	onActiveChanged: {
                                // This will fire properly, but active is always TRUE. Why? Because Active refers to the MouseArea.
                		if (active ) {
                			console.log("Drag is Active")
                		}
                		else {
                			console.log("Drag is InActive")
                		}
                	}
                }
                

                Change active to drag.active and it works as expected.

                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