Results 1 to 5 of 5

Thread: QListWidgetItem in Drag n' drop

  1. #1
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Exclamation QListWidgetItem in Drag n' drop

    Hi friends,

    I have a window of configuration of the toolbar on my application, running smoothly the drag n 'drop the items.
    I'm using QListWidgetItem with icons, but when you drag the item to another widget, the icon does not go with him. How can I improve this follow code in QMimeData?

    Qt Code:
    1. void ListAct::performDrag()
    2. {
    3. QListWidgetItem *item = currentItem();
    4. if (item)
    5. {
    6. QMimeData *mime = new QMimeData;
    7. mime->setText(item->text());
    8.  
    9. QDrag *drag = new QDrag(this);
    10. drag->setMimeData(mime);
    11.  
    12. if (drag->exec(Qt::MoveAction) == Qt::MoveAction)
    13. delete item;
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    Thanks,

    Marcelo E. Geyer
    Brazil/RS

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QListWidgetItem in Drag n' drop

    There is no need to implement DND by hand. It is already supported by the model view framework. See Using Drag and Drop with Item Views - Using Convenience Views for more details.
    J-P Nurmi

  3. #3
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QListWidgetItem in Drag n' drop

    Hi,

    Ok, I solved and now my items are moved between QListWidgets subclass. See the code below.
    I need is that when drag the item "Separator" (see the image) to another QListWidget subclass, the action is to copy (I believe that use Qt:: CopyAction) and not to move. To do this a few times I tried to write code but unsuccessful, reimplementation dropEvent. What happens and that by dragging up the other QListWidget, nothing happens, he does not copy the item.
    Based on the code that I have, what and how should I reimplement?

    Qt Code:
    1. ListAct::ListAct(QWidget *parent)
    2. :QListWidget(parent)
    3. {
    4. setViewMode(QListView::ListMode);
    5. setSelectionMode(QAbstractItemView::SingleSelection);
    6. setDragEnabled(TRUE);
    7. viewport()->setAcceptDrops(TRUE);
    8. setDropIndicatorShown(TRUE);
    9. setMovement(QListView::Snap);
    10. setUniformItemSizes(TRUE);
    11. setDragDropMode(QAbstractItemView::DragDrop);
    12. }
    13.  
    14. ListAct::~ListAct()
    15. {
    16.  
    17. }
    18.  
    19. void ListAct::addAct()
    20. {
    21. QListWidgetItem *sep = new QListWidgetItem(this);
    22. sep->setText(QString::fromUtf8("--- Separator ---"));
    23. sep->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
    24.  
    25. QListWidgetItem *item = new QListWidgetItem(this);
    26. item->setText(QString::fromUtf8("ItemTest1"));
    27. item->setIcon(QIcon(":/imagens/clients.png"));
    28. item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
    29.  
    30. QListWidgetItem *item2 = new QListWidgetItem(this);
    31. item2->setText(QString::fromUtf8("ItemTest2"));
    32. item2->setIcon(QIcon(":/imagens/clients.png"));
    33. item2->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
    34. }
    35.  
    36.  
    37. Qt::DropActions ListAct::supportedDropActions() const
    38. {
    39. return Qt::MoveAction; // | Qt::CopyAction
    40. }
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    Marcelo E. Geyer
    Attached Images Attached Images

  4. #4
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QListWidgetItem in Drag n' drop

    Hi friends,

    Posted this a while ago and now get back to this code. Can you help it? On this my last question posted?

    Thanks,

    Marcelo E. Geyer.

  5. #5
    Join Date
    Jan 2008
    Location
    Brasil
    Posts
    131
    Thanks
    18
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: QListWidgetItem in Drag n' drop

    Nobody can help me solve this?
    Thanks,

    Marcelo E. Geyer

Similar Threads

  1. Drag & drop with model/view (Qt4)
    By yogeshm02 in forum Qt Programming
    Replies: 16
    Last Post: 19th September 2011, 21:36
  2. Drag and Drop QTableWidget and QTableView
    By scorpion11 in forum Qt Programming
    Replies: 5
    Last Post: 8th April 2008, 10:33
  3. Strange behavior with Drag and Drop (not always drops)
    By Mona Shokrof in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2007, 19:00
  4. Replies: 7
    Last Post: 8th September 2006, 17:19
  5. Drag and drop revisited
    By Big Duck in forum Newbie
    Replies: 2
    Last Post: 30th June 2006, 17:41

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.