get control back on dragged items
-
hey guys,
I got an issue with Qt 5.15.2 and items dragged from a list...- the code :
draglist.h
#define DRAGLIST_H #include <QListWidget> #include <QMimeData> class DragList : public QListWidget { Q_OBJECT public: explicit DragList(QWidget *parent = nullptr); protected: QMimeData *mimeData(const QList<QListWidgetItem*> items) const { QString s=""; foreach (auto item, items) s += item->text() + "\n"; QMimeData *md = QListWidget::mimeData(items); md->setText(s.left(s.length()-1)); return md; } }; #endif // DRAGLIST_H
draglist.cpp
#include "draglist.h" DragList::DragList(QWidget *parent) : QListWidget(parent) { }
I use that very simple class to be able to drag items (url actually) from a QListWidget
So you can easily reproduce : just throw a QListWidget on a form and check its dragEnabled field, change its dragDropMode to DragOnly and promote it to DragList and voilà !
oh yes just add an entry to the list, let's say "https://www.google.com".
- The issue :
if you drag that item (https://www.google.com) and drop it into a Chrome window, it opens a google page and your item is still present into the QListWidget component. But do the very same thing with a Firefox window and your item disappears from the list.
.
- Solutions ?
Is there a way to tells Qt that items of this QlistWidget won't be transferred but only copied - no matter what - ? (knowing we already got the defaultDropAction of that QListWidget set to CopyAction, but i guess this property is about things dropped into that list, not about the action to take after one of its items was dropped)
Or is there a way to intercept the drop message to ignore it (as somehow chrome says to my Qt app "i copied that item" while firefox says "thank u for givin me that item, hope u won't miss it too much ;)")Thank you for your time, guys and hopefully your solutions :)
By the way i know as a workaround i might answer to the event of selection changing or item deletion by simply saving the selection before the drag and re-add the potentially missing items if needed, but I would like a more elegant solution which doesn't involve repairing the damage, but preventing it
- the code :