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. Drag and Drop to desktop or file manager
Forum Updated to NodeBB v4.3 + New Features

Drag and Drop to desktop or file manager

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 547 Views 2 Watching
  • 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.
  • fcarneyF Offline
    fcarneyF Offline
    fcarney
    wrote on last edited by
    #1

    This one is kinda fun. I currently have drag from the desktop/file manager working as my DropArea gets a url for me to use. Now I am trying to detect the drop area outside of the application.

                                            Drag.active: mouseArea.drag.active
                                            Drag.hotSpot.x: 0
                                            Drag.hotSpot.y: 0
                                            Drag.mimeData: { "text/uri-list": fileUrl }
                                            Drag.supportedActions: Qt.CopyAction
                                            Drag.dragType: Drag.Automatic
                                            Drag.onDragStarted: {
                                            }
                                            Drag.onDragFinished: {
                                                
                                                if(dropAction === Qt.CopyAction){
                                                    console.log("drag copy")
                                                }
                                            }
    

    I have 2 problems.

    • How do I detect if this landed in a DropArea or outside the app?
    • How do I detect where it dropped outside the app? (there is no DropArea for this)

    In the above code I see the "drag copy" message get printed as expected when dropping outside the app. I cannot see anything in the docs to indicate how to get the drop area/url that I dropped to outside the app. Is there a global drop area or something?

    C++ is a perfectly valid school of magic.

    S 1 Reply Last reply
    0
    • fcarneyF fcarney

      This one is kinda fun. I currently have drag from the desktop/file manager working as my DropArea gets a url for me to use. Now I am trying to detect the drop area outside of the application.

                                              Drag.active: mouseArea.drag.active
                                              Drag.hotSpot.x: 0
                                              Drag.hotSpot.y: 0
                                              Drag.mimeData: { "text/uri-list": fileUrl }
                                              Drag.supportedActions: Qt.CopyAction
                                              Drag.dragType: Drag.Automatic
                                              Drag.onDragStarted: {
                                              }
                                              Drag.onDragFinished: {
                                                  
                                                  if(dropAction === Qt.CopyAction){
                                                      console.log("drag copy")
                                                  }
                                              }
      

      I have 2 problems.

      • How do I detect if this landed in a DropArea or outside the app?
      • How do I detect where it dropped outside the app? (there is no DropArea for this)

      In the above code I see the "drag copy" message get printed as expected when dropping outside the app. I cannot see anything in the docs to indicate how to get the drop area/url that I dropped to outside the app. Is there a global drop area or something?

      S Offline
      S Offline
      Sanderv
      wrote on last edited by
      #2

      Replying here just because it's the first hit on google for Drag.Automatic: there is an answer to this question here: https://stackoverflow.com/questions/24532317/new-drag-and-drop-mechanism-does-not-work-as-expected-in-qt-quick-qt-5-3. In short, you should replace

      Drag.active: mouseArea.drag.active
      

      by

      property bool dragActive: mouseArea.drag.active
      
      onDragActiveChanged: {
          if (dragActive) {
              Drag.start();
          } else {
              Drag.drop();
          }
      }
      

      More details in the SO post, apparently you can see the different code flows in the QQuickDrag code. Note that Drag.Automatic does work as expected when you use a DragHandler, just not when you use a MouseArea.

      1 Reply Last reply
      1

      • Login

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