In this project example, if you drag and drop a .wav file on a SoundEffectWidget, you can change the sound being played. The constructor of SoundEffectWidget performs a specific task to allow you to drag and drop:
setAcceptDrops(true);
We can now override the drag-and-drop callbacks. Let's start with the dragEnterEvent() function:
//SoundEffectWidget.h class SoundEffectWidget : public QWidget { ... protected: void dragEnterEvent(QDragEnterEvent* event) override; ... }; //SoundEffectWidget.cpp void SoundEffectWidget::dragEnterEvent(QDragEnterEvent* event) { if (event->mimeData()->hasFormat("text/uri-list")) { event->acceptProposedAction(); } }
The dragEnterEvent() function is called each time the user drags an object on the widget. In our case, we only want to allow dragging and...