PDA

View Full Version : Qt Drag and Drop between two QListWidget (Removing and restoring items)



wallacesoh
15th January 2014, 02:55
I have two list widgets, list1 and list2. With the following codes, I am able to drag and drop between the two list widgets.


QListWidget *list1 = new QListWidget(this);
QListWidgetItem *__qlistwidgetitem = new QListWidgetItem(list1);
__qlistwidgetitem->setIcon(icon);
...
list1->setDragEnabled(true);
list1->setDragDropMode(QAbstractItemView::DragDrop);

QListWidget *list2 = new QListWidget(this);
list2->setDragDropOverwriteMode(true);
list2->setDragDropMode(QAbstractItemView::DragDrop);

However, when I drag an item from list1 and drop into list2, the item stays in list1. I would want the item to be moved into list2. Another problem is that how can I, with a click of a tool button, clear the item from list2 back into list1?

Appreciate any help. Thanks!

wallacesoh
23rd January 2014, 06:49
Is there anyone who can help me with this?

Thanks!

anda_skoa
23rd January 2014, 08:43
Have you tried overwriting QAbstractItemView::startDrag() and changing the flags to make "move" the only action?

For the button click action, just take the item from one view and add it to the other.

Cheers,
_