Items after dropping from widget to widget missing
-
wrote on 11 May 2019, 11:38 last edited by Huy Manh 5 Nov 2019, 12:11
After dragging and dropping an item from a list widget to a list widget, the item disappears in the target list widget.
I used eventFilter for only the list widgets in MainWindow.
bool MainWindow::eventFilter(QObject *target,QEvent *event){ if (event->type() == QEvent::DragEnter) { QDragEnterEvent *tDragEnterEvent = static_cast<QDragEnterEvent *>(event); tDragEnterEvent->acceptProposedAction(); return true; } else if (event->type() == QEvent::DragMove) { QDragMoveEvent *tDragMoveEvent = static_cast<QDragMoveEvent *>(event); tDragMoveEvent->acceptProposedAction(); return true; } else if (event->type() == QEvent::Drop) { QDropEvent *tDropEvent = static_cast<QDropEvent *>(event); tDropEvent->acceptProposedAction(); qDebug() << "OK, execute your task!"; return true; } else { // standard event processing return QObject::eventFilter(target, event); } //return false; } //in MainWindow constructor ui->listWidget->installEventFilter(this);
qDebug showed the debug string after dropping but the item went missing.
-
You filter out the drop events and the wonder why the widget which should receive them don't receive them? Mhh.
-
wrote on 11 May 2019, 12:09 last edited by
Sorry but I don't know your meaning, I've been using Qt for about 3 months and this is the first time I handle events, so I hope you can help me with this minor problem, thank you.
-
See documentation for QObject::eventFilter(): "... if you want to filter the event out, i.e. stop it being handled further, return true; ..." which is exactly what you're doing.
-
wrote on 11 May 2019, 12:27 last edited by Huy Manh 5 Nov 2019, 12:28
Oh, I get it. Can you suggest for me a solution? That is, if I drop an item into the list widget, I have a variable "count" plus 1 and if I drag an item out, "count" minus 1. I thought at first that eventFilter will help me.
-
Drag'n'Drop from a QListWidget to another QListWidget should work out-of-the-box if dragEnabled/acceptDrops is active - see documentation
5/6