1 Star 2 Fork 0

toby20130333/QMLDragDrop

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DragAndDropTextItem.qml 2.37 KB
一键复制 编辑 原始数据 按行查看 历史
toby20130333 提交于 2015-06-01 23:03 . add new qml file

import QtQuick 2.2
Rectangle {
id: item
property string display
property string imgurl: ""
property string dropTxt: ""
property color entercolor
property color exitcolor
color: "#EEE"
signal destorySelf();
width: 200
height: 200
Image {
id: imgTag
source: imgurl
anchors.top: parent.top
width: 96
height: 96
anchors.horizontalCenter: parent.horizontalCenter
}
Text {
horizontalAlignment: Text.AlignHCenter
text: item.display
width: 100
wrapMode: Text.WordWrap
anchors.top: imgTag.bottom
anchors.horizontalCenter: parent.horizontalCenter
}
DropArea {
anchors.fill: parent
keys: ["text/plain","text/uri-list"]
onEntered: {
item.color = entercolor;
}
onExited: {
item.color = exitcolor;
}
onDropped: {
console.log("drop end......................"+display+" this item memory ID drop text: "+drop.text)
dropTxt = drop.text;
item.color = exitcolor;
if (drop.hasText && display != drop.text) {
if (drop.proposedAction == Qt.MoveAction || drop.proposedAction == Qt.CopyAction) {
item.display = display+"+"+drop.text
drop.acceptProposedAction()
}
if(drop.hasUrls){
console.log("url "+drop.urls);
}
}
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
drag.target: draggable
}
Item {
id: draggable
anchors.fill: parent
Drag.active: mouseArea.drag.active
Drag.hotSpot.x: 0
Drag.hotSpot.y: 0
Drag.mimeData: { "text/plain": item.display,"text/uri-list":item.imgurl }
Drag.dragType: Drag.Automatic
Drag.onDragStarted: {
}
Drag.onDragFinished: {
console.log("drop end...........1111..........."+display+" this item memory ID drop text: "+dropTxt)
if (dropAction == Qt.MoveAction) {
console.log("drop MoveAction......................"+display+" also this item memory ID: "+item)
item.display = ""
destorySelf();
}
}
} // Item
function destorymyself(){
item.destroy();
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/duoduozhijiao/QMLDragDrop.git
[email protected]:duoduozhijiao/QMLDragDrop.git
duoduozhijiao
QMLDragDrop
QMLDragDrop
master

搜索帮助