PDA

View Full Version : dropEvent doesn't happen without mousemove



Dimon
6th October 2009, 16:49
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:


void QMyWidget::mousePressEvent(QMouseEvent* pMe)
{

if (pMe->button() == Qt::LeftButton)
m_ptDragPos = pMe->pos();

QWidget::mousePressEvent(pMe);
}

void QMyWidget::mouseMoveEvent(QMouseEvent* pMe)
{
if (pMe->buttons() & Qt::LeftButton)
{
if ((pMe->pos() - m_ptDragPos).manhattanLength() > QApplication::startDragDistance())
{
QMimeData* pData = new QMimeData;
pData->setText(QString("Test"));
QDrag* pDrag = new QDrag(this);

pDrag->setMimeData(pData);

pDrag->exec(Qt::MoveAction);
}
}

QWidget::mouseMoveEvent(pMe);
}

void QMyWidget::dragEnterEvent(QDragEnterEvent* pe)
{
pe->acceptProposedAction();
}

void QMyWidget::dragMoveEvent(QDragMoveEvent* pe)
{
if (pe->mimeData()->hasText() )
pe->acceptProposedAction();
}

void QMyWidget::dropEvent(QDropEvent* pe)
{
QMyWidget* src = qobject_cast<QMyWidget*>(pe->source());
if (src && src != this)
pe->acceptProposedAction();

}
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

QOleDropTarget::Drop(LPDATAOBJECT /*pDataObj*/, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect) 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.