如何使TableView项可拖动

时间:2013-07-03 06:46:32

标签: qml qtquick2

我有一个TableView,并为它实现了我自己的项目委托。我希望能够将它拖出来并放在其他地方。我该怎么做

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。我怎么也这样做?

{Qt 5.1 RC 1 - Win7 - MinGw 4.8}

0 个答案:

没有答案