Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.5.3
-
None
-
020b10e8288c981bffe1a6470ece25ec6c532b73, 247e3637c41cc14d174a1170957274fb8a9400b4
Description
When using Drag/Drop with the Cocoa build of Qt, the drag/drop icon does not update itself appropriately when the curor enters an invalid drop area.
In MyWidget::dragEnterEvent(), we call
event->accept()
to ensure that the drag-move events within the widget are successfully processed.
Next, in MyWidget::dragMoveEvent(), we perform
if (dragIsValidForDrop(event)) event->acceptProposedAction(); else event->ignore()
Thus, we can selectively choose which areas of the QWidget (we have custom data drawn, and depending on where the drop occurs, it might be valid or not), which is performed in dragIsValidForDrop(event).
In MyWidget::dropEvent(), we perform a similar function:
if (dragIsValidForDrop(event))
... process the drop here...
When initiating a drag from within our application with Qt::CopyAction, the cursor and icon appears with the '' symbol indicating the drop is valid. However, regardless of whether dragMoveEvent() accepts or ignores the event, the '' symbol appears with the cursor indicating that the drop is valid when it's not.
This behaviour can be replicated with a minor modification to the 'fridgemagnet' example code:
In dragwidget.cpp, add the following:
void DragWidget::dragMoveEvent(QDragMoveEvent *event) { if (event->pos().y() < rect().height()/2) { event->ignore(); return; } ... remainder of example code here ... } void DragWidget::dropEvent(QDropEvent *event) { if (event->pos().y() < rect().height()/2) return; ... remainder of example code here ... }
Compile the example code using Cocoa. Trying to drop a magnet in the upper half of the window should be invalid, and the dragged item does fall back to it's original location by being denied by dropEvent().
HOWEVER there is no visual feedback that this drop isn't allowed; the cursor does not change to show that it's disallowed.
Building the same code on Linux and Windows works correctly.