1 Star 2 Fork 0

toby20130333/QMLDragDrop

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.qml 4.53 KB
一键复制 编辑 原始数据 按行查看 历史
toby20130333 提交于 2015-06-01 23:03 . add new qml file
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
ApplicationWindow {
title: qsTr("Hello World")
width: 640
height: 480
visible: true
ListView {
id: listView
width: parent.width
height: parent.height
property int dragItemIndex: -1
property bool isCurrentItem: false
model: ListModel {
id:lstModel
Component.onCompleted: {
for (var i = 1; i < 4; ++i) {
append({value: i+"Value"});
}
}
}
delegate: Item {
id: delegateItem
width: 100
height: 100
Rectangle {
id: dragRect
width: delegateItem.width
height: delegateItem.width
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
color: "salmon"
border.color: Qt.darker(color)
Text {
id:curTxt
anchors.centerIn: parent
text: modelData
}
MouseArea {
id: mouseArea
anchors.fill: parent
drag.target: dragRect
Drag.mimeData: { "text/plain":modelData }
drag.onActiveChanged: {
if (mouseArea.drag.active) {
listView.dragItemIndex = index;
listView.isCurrentItem = true;
listView.currentIndex = index;
}
dragRect.z = 10;
console.log("current drag..................................."+index);
dragRect.Drag.drop();
}
}
states: [
State {
when: dragRect.Drag.active
ParentChange {
target: dragRect
parent: delegateItem
}
AnchorChanges {
target: dragRect
anchors.horizontalCenter: undefined
anchors.verticalCenter: undefined
}
}
]
DropArea {
id: dropArea2
anchors.fill: parent
keys:["text/plain"]
onDropped: {
dragRect.z = 0;
console.log("current index-----text--------------" +drop.text);
if(listView.currentIndex != index)
{
console.log("拖到ID为: "+curTxt.text+" 控件");
console.log("被拖动的控件ID......."+listView.dragItemIndex);
console.log("this drag item is "+lstModel.get(listView.dragItemIndex).value)
listView.model.remove(listView.dragItemIndex);
listView.dragItemIndex = -1;
}
}
}
Drag.active: mouseArea.drag.active
Drag.hotSpot.x: dragRect.width / 2
Drag.hotSpot.y: dragRect.height / 2
}
}
}
// ListView {
// id: listViewCopy
// width: parent.width / 3
// height: parent.height
// anchors.left: listView.right
// anchors.right: rightRect.left
// delegate: Item {
// id: delegateItemCopy
// width: listView.width
// height: 50
// }
// }
// Rectangle {
// id:rightRect
// width: parent.width / 3
// height: parent.height
// anchors.right: parent.right
// color: "#aaff0011"
// DropArea {
// id: dropArea
// anchors.fill: parent
// onDropped: {
// console.log("drop in this area...............");
// listView.model.remove(listView.dragItemIndex);
// listView.dragItemIndex = -1;
// }
// }
// }
function createItem(){
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/duoduozhijiao/QMLDragDrop.git
[email protected]:duoduozhijiao/QMLDragDrop.git
duoduozhijiao
QMLDragDrop
QMLDragDrop
master

搜索帮助