Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Dropping a new item into a drag-droppable GridView

$
0
0
I am trying to modify the GridView drag & drop example provided here: http://doc.qt.io/qt-5/qtquick-draganddrop-example.html I’m using Qt 5.4, QtQuick 2.4, QtQml.Models 2.1. The existing code allows drag and drop within the GridView. My desired additional functionality: drag a new (external) item into the grid view so that it would be inserted into the model in the proper position. I added this external item (note, topRect is the root rectangle, with width: 520; height: 600) Rectangle {         id: sourceRect         z:9         color: "blue"           width: 80; height: 80         x: topRect.width - 80         y: 0         Drag.active: dragArea.drag.active         Drag.hotSpot.x: 40         Drag.hotSpot.y: 40         Drag.source: topRect           MouseArea {             id: dragArea             anchors.fill: parent             drag.target: parent         }     } I added a small indicator to the rectangle, to see where insertion would take place. Rectangle { id: indicatorRect  width: 10  height: icon.height  anchors.top: icon.top  anchors.left: icon.left  color: "green"  visible: false } And this is my modified DropArea part of the delegate: DropArea {  anchors { fill: parent; margins: 15 }  onEntered: {                       if (drag.source.visualIndex === undefined)   {    indicatorRect.visible = true;   }                           else    visualModel.items.move(drag.source.visualIndex, delegateRoot.visualIndex)  }    onDropped:  {   console.log("Dropped...") // PROBLEM: this never happens  }    onExited:  {   if (drag.source.visualIndex === undefined)   {    indicatorRect.visible = false;   }  } } The problem: the onDropped code is not called. My entered/exited correctly shows/hides the indicator rectangle but when I stop dragging, I don’t get the onDropped line to hit.

Viewing all articles
Browse latest Browse all 4972

Latest Images

Trending Articles



Latest Images