Qml 如何使TableView项可拖动
我有一个TableView,并为它实现了我自己的项委托。我想把它拖出来放到别的地方。我该怎么做Qml 如何使TableView项可拖动,qml,qtquick2,Qml,Qtquick2,我有一个TableView,并为它实现了我自己的项委托。我想把它拖出来放到别的地方。我该怎么做 itemDelegate: Text { id: objMainText anchors.horizontalCenter: parent.horizontalCenter elide: styleData.elideMode color: "yellow" text: styleData.value.get(0).content //assume this
itemDelegate: Text {
id: objMainText
anchors.horizontalCenter: parent.horizontalCenter
elide: styleData.elideMode
color: "yellow"
text: styleData.value.get(0).content //assume this is correct
MouseArea {
id: objDragArea
anchors.fill: parent
drag.target: objDragableText
drag.axis: Drag.XAndYAxis
hoverEnabled: true
onEntered: {
console.log("Hover Captured") //This gets printed
}
onClicked: {
console.log("Detected") //This NEVER gets printed
}
Text {
id: objDragableText
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
Drag.active: objDragArea.drag.active
opacity: Drag.active / 2
text: objMainText.text
color: objMainText.color
states: State {
when: { objDragArea.drag.active }
AnchorChanges {
anchors.horizontalCenter: undefined
anchors.verticalCenter: undefined
}
}
}
}
}
不要介意这里和那里是否少了几个括号。我当然会照顾那些人。但是为什么我不能拖动objDragableText
,我该怎么做呢?
此外,onClicked
会像上面的注释一样被捕获,但不会被onPressed
捕获。我该怎么做呢
{qt5.1rc1-Win7-mingw4.8}