3

I’ve a TableView and have implemented my own item delegate for it. I want to be able to drag it out and place it somewhere else. How do I do it

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
                }
            }
        }
    }
}

Don’t mind if there are a few brackets less here and there. Those I’m taking care of ofcourse. But why can’t I drag objDragableText and how do i do it? Also, onClicked is captured as in the comments above but not onPressed. How do I also do this?

{Qt 5.1 RC 1 - Win7 - MinGw 4.8}

4

0 回答 0