I have a QDialog with two QListWidgets. The user can copy items from the first list (availableItemsList) to the second (myList) via drag and drop. There he can reorder them and then confirm the dialog. I would like the user to be able to remove an item from the second list via drag and drop by simply dropping it outside the list widget; so far this is only possible by selecting the item and hitting delete.

The idea was to remove an item on receiving the DragLeaveEvent. To realize this, I have tried installing an event filter on the list widget (myList), but the DragLeaveEvent is never fired, even though the mouse cursor changes to the "not allowed" sign when an item is dragged outside myList, and neither is the DragEnterEvent fired every time I would expect it to be, not even when I drag a new item from the availableItemsList to myList. Here is my code (so far only qDebug output, no removal of the item):

Qt Code:
  1. MyDialog::MyDialog(QWidget *parent) :
  2. QDialog(parent),
  3. ui(new Ui::MyDialog)
  4. {
  5. /* ... */
  6. ui->myList->installEventFilter(this);
  7. }
  8.  
  9. bool MyDialog::eventFilter(QObject *obj, QEvent *event)
  10. {
  11. qDebug() << "Event Filter called with " << event->type();
  12. if (event->type() == QEvent::DragLeave) {
  13. qDebug() << event->type() << "= drag leave event.";
  14. return true;
  15. } else if (event->type() == QEvent::DragEnter) {
  16. qDebug() << event->type() << "= drag enter event.";
  17. return true;
  18. } else {
  19. // standard event processing
  20. return QObject::eventFilter(obj, event);
  21. }
  22. }
To copy to clipboard, switch view to plain text mode 

List properties (dialog created with Qt Designer):

List 1 (availableItemsList):
- acceptDrops: false
- dragEnabled: false
- dragDropOverwriteMode: false
- dragDropMode: DragOnly
- defaultDropAction: IgnoreAction

List 2 (myList):
- acceptDrops: true (if value is set to false, nothing changes)
- dragEnabled: true (if value is set to false, nothing changes)
- dragDropOverwriteMode: true
- dragDropMode: DragDrop
- defaultDropAction: MoveAction