Hi

I'm using Drag'n'Drgop with Qt. The drag is started in one widget and ends in the other widget. When I release the mouse the DropEvent is called. But sometimes, when I release the left mouse button over the target widget, the QDrag::exec() doesn't return (dropEvent() on the target widget does not called), until the mouse is not moved. In this case, I need to move a mouse at list 1 pix after releasing the left button and then dropEvent() is called.

Here is the code:

Qt Code:
  1. void QMyWidget::mousePressEvent(QMouseEvent* pMe)
  2. {
  3.  
  4. if (pMe->button() == Qt::LeftButton)
  5. m_ptDragPos = pMe->pos();
  6.  
  7. QWidget::mousePressEvent(pMe);
  8. }
  9.  
  10. void QMyWidget::mouseMoveEvent(QMouseEvent* pMe)
  11. {
  12. if (pMe->buttons() & Qt::LeftButton)
  13. {
  14. if ((pMe->pos() - m_ptDragPos).manhattanLength() > QApplication::startDragDistance())
  15. {
  16. QMimeData* pData = new QMimeData;
  17. pData->setText(QString("Test"));
  18. QDrag* pDrag = new QDrag(this);
  19.  
  20. pDrag->setMimeData(pData);
  21.  
  22. pDrag->exec(Qt::MoveAction);
  23. }
  24. }
  25.  
  26. QWidget::mouseMoveEvent(pMe);
  27. }
  28.  
  29. void QMyWidget::dragEnterEvent(QDragEnterEvent* pe)
  30. {
  31. pe->acceptProposedAction();
  32. }
  33.  
  34. void QMyWidget::dragMoveEvent(QDragMoveEvent* pe)
  35. {
  36. if (pe->mimeData()->hasText() )
  37. pe->acceptProposedAction();
  38. }
  39.  
  40. void QMyWidget::dropEvent(QDropEvent* pe)
  41. {
  42. QMyWidget* src = qobject_cast<QMyWidget*>(pe->source());
  43. if (src && src != this)
  44. pe->acceptProposedAction();
  45.  
  46. }
To copy to clipboard, switch view to plain text mode 
The drag&drop occured between two instances of the QMyWidget class. Tracing into
Qt src I noticed, that Qt get the drop event from Ole32 the same way. Method
Qt Code:
  1. QOleDropTarget::Drop(LPDATAOBJECT /*pDataObj*/, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
To copy to clipboard, switch view to plain text mode 
from qdnd_win.cpp file often get control only after mouse moved. At the same time, Windows applications (Explorer, Word and so on ...) never has the same problem.

Could anyone help me with this issue? May be I forget something very simple?

Best regards.