Drag and Drop in Qt 4.5

Recently I was working on a Qt app requiring Drag and Drop support. The documentation says that to use this on a QWidget, we need to set
dialog.setAcceptDrops(true);
I tried that but the cursor still showed the “not -allowed” symbol. This was bit confusing making me think that there's some internal problem. But actually the implementation of the following event handlers is mandatory to make it work-
 

void Dialog::dragEnterEvent(QDragEnterEvent *event)

{

event->acceptProposedAction();

}

 

void ChatDialog::dragMoveEvent(QDragMoveEvent *event)

{

event->acceptProposedAction();

}

 


This is provided so that app can accept only certain types of files. Hope this helps someone.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s