PDA

View Full Version : Drag and Drop between 2 QListWidgets



ShamusVW
19th April 2010, 09:57
I have been trying to get my drag & drop working between 2 QListWidgets, and have read a few of the other posts on this topic, however, I still don't know how to get it working correctly, so if someone can assist me on this please.

In Design Mode (QtCreator) I have 2 QListWidgets. I populate the first one.
I want to be able to drag and drop items between the 2 lists. I have it "almost" working. The issue I have, when I drag it out the list, it leaves an "empty" place in the list, I want it to fill up the gap with the remaining items.
Also, I have some odd behaviour. Even though I have "acceptDrops" not selected, it still allows items to be dropped and placed into the list. I am obviously not understanding the settings.

These are my settings:
acceptDrops - not selected
showDropIndicator - selected
dragEnabled - selected
dragDropOverWriteMode - selected
dragDropMode - DragDrop
defaultDropAction - TargetMoveAction

Thanks,
Shaun

ShamusVW
19th April 2010, 10:45
I am actually having some strange behaviour. If I set both QListWidgets's properties the same with dragDropMode set to DragOnly and defaultDropAction now set to MoveAction, then I can't drag out of either (I also as a test populated the second list). If I set the first QListWidget to DragDrop, then suddenly I can drag out the first into the second, and now also drag out the second back into the first!? In this case the second wasn't pre-populated.

shankarnag
27th April 2010, 08:55
There are some functions which will handle drag and drop options, similar to below functions

list->setSelectionMode(QAbstractItemView::SingleSelectio n);
list->setDragEnabled(true);
list->setDragDropMode(QAbstractItemView::InternalMove);
list->viewport()->setAcceptDrops(true);

list->setDropIndicatorShown(true);

list1->setSelectionMode(QAbstractItemView::SingleSelectio n);
list1->setDragEnabled(true);
list1->viewport()->setAcceptDrops(true);

list1->setDropIndicatorShown(true);

ShamusVW
28th April 2010, 14:06
If I understand, the property "acceptDrops" would determine if items can be dropped onto the QListWidget.
However, on both of the QListWidgets, I have this unchecked, yet can still move items between the two (Windows 7). However, when I move this application to Windows XP, it doesn't allow drops, even if I change both QListWidgets to acceptDrops.
Can someone shed some light on this?

ShamusVW
28th April 2010, 14:42
On Windows 7, if I have the right QListWidget dragDropMode set to DragOnly, I can drop to it and drag from it, but not on XP. For this to work on XP, it must be set to DragDrop, which makes sense. It would seem that Windows 7 is letting this slip?