Results 1 to 5 of 5

Thread: Drag and Drop between 2 QListWidgets

  1. #1
    Join Date
    Oct 2009
    Location
    South Africa
    Posts
    94
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Drag and Drop between 2 QListWidgets

    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

  2. #2
    Join Date
    Oct 2009
    Location
    South Africa
    Posts
    94
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag and Drop between 2 QListWidgets

    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.

  3. #3

    Default Re: Drag and Drop between 2 QListWidgets

    There are some functions which will handle drag and drop options, similar to below functions

    list->setSelectionMode(QAbstractItemView::SingleSelecti on);
    list->setDragEnabled(true);
    list->setDragDropMode(QAbstractItemView::InternalMove );
    list->viewport()->setAcceptDrops(true);

    list->setDropIndicatorShown(true);

    list1->setSelectionMode(QAbstractItemView::SingleSelecti on);
    list1->setDragEnabled(true);
    list1->viewport()->setAcceptDrops(true);

    list1->setDropIndicatorShown(true);

  4. #4
    Join Date
    Oct 2009
    Location
    South Africa
    Posts
    94
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag and Drop between 2 QListWidgets

    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?

  5. #5
    Join Date
    Oct 2009
    Location
    South Africa
    Posts
    94
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag and Drop between 2 QListWidgets

    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?

Similar Threads

  1. two qlistwidgets
    By msmihai in forum Newbie
    Replies: 1
    Last Post: 8th January 2009, 15:00
  2. Drag Drop Help pls
    By munna in forum Qt Programming
    Replies: 7
    Last Post: 4th September 2006, 12:11
  3. drag and drop
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 26th April 2006, 11:46
  4. drag and drop
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 12th April 2006, 11:54
  5. drag and drop
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2006, 11:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.