5
在Qml中,我可以使用text/uri-list
mime類型開始拖動,以便從我的應用程序開始複製操作到文件瀏覽器,例如,將文件從應用程序拖到資源管理器。我的應用程序可以進行復制嗎?
Item {
id: draggable
anchors.fill: parent
Drag.active: mouseArea.drag.active
Drag.hotSpot.x: 0
Drag.hotSpot.y: 0
Drag.mimeData: { "text/uri-list": "file:///home/myname/Desktop/avatar.jpeg" }
Drag.supportedActions: Qt.CopyAction
Drag.dragType: Drag.Automatic
Drag.onDragStarted: { }
Drag.onDragFinished: {
console.log("Time to copy")
}
} // Item
或
Item {
id: draggable
anchors.fill: parent
Drag.active: mouseArea.drag.active
Drag.hotSpot.x: 0
Drag.hotSpot.y: 0
Drag.mimeData: { "text/uri-list": "https://farm1.staticflickr.com/713/21777111068_e3310cfb94_k.jpg" }
Drag.supportedActions: Qt.CopyAction
Drag.dragType: Drag.Automatic
Drag.onDragStarted: { }
Drag.onDragFinished: {
console.log("Time to copy")
}
} // Item
(見Qt Quick Examples - externaldraganddrop)
這工作正常,賦予file:
和http:
的URI。
但是我的真實數據不能作爲URI使用,但存儲在數據庫中。我無法快速存儲到臨時數據,因爲這可能需要幾秒鐘的時間,並且用戶在開始拖動時不想延遲。
是否有可能在刪除後獲取目標URI並自己複製?或者只能對目標進行復制?
在後面的例子中,我是否需要通過內部HTTP服務器使我的數據可用?我怎麼知道Linux,Windows和OS X上的文件瀏覽器支持哪種URI方案?
嗯,是的,如果沒有更好的方法,這必須完成。數據甚至可以從數據庫傳輸到HTTP服務器,因此根本沒有等待。如果我完成了,我想我會在我的實施中添加詳細的博客帖子。在此之前,我仍然希望有一個更簡單的把戲。 –