import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
Rectangle
{
width: 640
height: 450
ListModel
{
id: objmodel
ListElement
{
name: "张飞"
}
ListElement
{
name: "华佗"
}
ListElement
{
name: "朱治"
}
ListElement
{
name: "公孙度"
}
ListElement
{
name: "袁本初"
}
ListElement
{
name: "杨松"
}
}
Component
{
id: delegateItem
Item
{
id: wrapper
width: parent.width
height: 30
Text
{
id: coll
text: name
font.pointSize: 13
color: wrapper.ListView.isCurrentItem? "red":"black"
}
MouseArea
{
id: mousearea
anchors.fill: parent
onClicked:listview.currentIndex = index;
onMouseXChanged:
{
var pore = listview.indexAt(mousearea.mouseX + wrapper.x, mousearea.mouseY + wrapper.y);
if(index !== pore )
{
objmodel.move(index,pore,1)
}
}
onMouseYChanged:
{
var pore = listview.indexAt(mousearea.mouseX + wrapper.x, mousearea.mouseY + wrapper.y);
if(index !== pore)
{
objmodel.move(index,pore,1)
}
}
}
}
}
ListView
{
id: listview
width:240
height:180
anchors.centerIn: parent
delegate: delegateItem
model:objmodel
interactive: false
focus: true
move: Transition
{
NumberAnimation { properties: "x,y"; duration: 2100 }
}
}
}