rwik
rwik

Reputation: 785

How to show custom icon during drag in qtquick?

I am trying to apply drag drop functionality in my qml app. I able to drag and drop objects. But during drag , instead of moving source object, i would like show custom icon and pass some text data to drop area. Please let me know how this is possible in qml ?

Upvotes: 0

Views: 646

Answers (1)

Orest Hera
Orest Hera

Reputation: 6776

There is a property that indicates that an object is being dragged: Drag.active. In QML object properties can be directly bound to other properties, for example:

Rectangle {
        x: 10; y: 10;
        width: Drag.active ? 60 : 80;
        height: Drag.active ? 60 : 80;
        color: Drag.active ? "red" : "blue"

        Drag.active: dragArea.drag.active

        Text {
            text: "DRAGGING"
            visible: parent.Drag.active
        }
        MouseArea {
            id: dragArea
            anchors.fill: parent
            drag.target: parent
        }
    }

This blue rectance changes its color to red when it is moving. Its size in motion is smaller and also the child text object is visible.

You can have an item with hidden image that becomes visible during dragging.

Upvotes: 1

Related Questions