Results 1 to 3 of 3

Thread: Qt Drag and Drop between two QListWidget (Removing and restoring items)

  1. #1

    Exclamation Qt Drag and Drop between two QListWidget (Removing and restoring items)

    I have two list widgets, list1 and list2. With the following codes, I am able to drag and drop between the two list widgets.

    Qt Code:
    1. QListWidget *list1 = new QListWidget(this);
    2. QListWidgetItem *__qlistwidgetitem = new QListWidgetItem(list1);
    3. __qlistwidgetitem->setIcon(icon);
    4. ...
    5. list1->setDragEnabled(true);
    6. list1->setDragDropMode(QAbstractItemView::DragDrop);
    7.  
    8. QListWidget *list2 = new QListWidget(this);
    9. list2->setDragDropOverwriteMode(true);
    10. list2->setDragDropMode(QAbstractItemView::DragDrop);
    To copy to clipboard, switch view to plain text mode 

    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!

  2. #2

    Default Re: Qt Drag and Drop between two QListWidget (Removing and restoring items)

    Is there anyone who can help me with this?

    Thanks!

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Drag and Drop between two QListWidget (Removing and restoring items)

    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,
    _

Similar Threads

  1. to use drag & drop on QListWidget
    By giorgik in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2012, 19:00
  2. Drag and Drop items in QListWidget
    By tommynator128 in forum Qt Programming
    Replies: 4
    Last Post: 10th March 2011, 12:09
  3. Drag and drop between QListWidget's
    By estanisgeyer in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2011, 05:29
  4. Replies: 3
    Last Post: 10th June 2010, 16:13
  5. Replies: 1
    Last Post: 22nd October 2009, 01:02

Tags for this Thread

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.