If you can read my code this QListWidget can drag drop multile items as icon.. and text
from attribute hotels sauna bar, ecc..

Qt Code:
  1. class IconScroller : public QListWidget
  2. {
  3. Q_OBJECT
  4. //
  5. public:
  6. IconScroller( bool enable = false , QWidget* parent = 0 )
  7. : QListWidget( parent )
  8. {
  9. enableout = enable;
  10. setSelectionMode ( QAbstractItemView::ExtendedSelection );
  11. setAcceptDrops(true);
  12. setDropIndicatorShown(false);
  13. if (enable) {
  14. setDragEnabled(true);
  15. }
  16. ///////setIconSize ( QSize(80,80));
  17. }
  18.  
  19. void mousePressEvent(QMouseEvent *event)
  20. {
  21. if (enableout) {
  22. QListWidgetItem *child = itemAt(event->pos());
  23. if (!child) {
  24. return;
  25. }
  26. /* IcoLine = hotel attribut icon mit beschreibung in 6 sprachen und
  27.   int kategorie int id + pixmap 30x30 */
  28. IcoLine Io = child->data(Qt::UserRole).value<IcoLine>();
  29.  
  30. QPixmap dragicon = Io.pix().scaledToWidth(Io.pix().width() * 3); /* zoom it */
  31. /* TabIcone liste von IcoLine */
  32. TabIcone dd;
  33. dd.all_lines.append(Io);
  34.  
  35. QList<QListWidgetItem *> tutti = selectedItems();
  36.  
  37. for (int i=0; i<tutti.size(); i++) {
  38. QListWidgetItem *pane = tutti[i];
  39. IcoLine Iter = pane->data(Qt::UserRole).value<IcoLine>();
  40. dd.all_lines.append(Iter);
  41. }
  42.  
  43. QString stream = SaveTabelicon(dd); /* QDataStream zu toBase64 fuer sql*/
  44. QMimeData *mimeData = new QMimeData;
  45. mimeData->setData("application/x-atticonhotel",stream.toUtf8());
  46.  
  47. QDrag *drag = new QDrag(this);
  48. drag->setMimeData(mimeData);
  49. drag->setPixmap(dragicon);
  50. ///////drag->setHotSpot(event->pos() - ????? ); //////
  51. /* make pixmap large and setHotSpot not need */
  52.  
  53. if (drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction) {
  54. qDebug() << "### drag move it " << Io.id();
  55. }
  56.  
  57. }
  58.  
  59. QListWidget::mousePressEvent(event);
  60. }
  61. void dropEvent(QDropEvent *event)
  62. {
  63. ///////qDebug() << "### dropEvent";
  64. if (event->mimeData()->hasFormat("application/x-atticonhotel")) {
  65. QByteArray itemData = event->mimeData()->data("application/x-atticonhotel");
  66. //////////qDebug() << "### dropEvent entra siiiiiiiiiiii ";
  67. QString daten = QString::fromUtf8(itemData.data());
  68. TabIcone liste = OpenTabelicon(daten);
  69. emit AppendList(liste);
  70. event->accept();
  71.  
  72. } else {
  73. event->ignore();
  74. }
  75. }
  76.  
  77.  
  78.  
  79. void dragEnterEvent(QDragEnterEvent *event)
  80. {
  81. qDebug() << "### dragEnterEvent ";
  82.  
  83. if (event->mimeData()->hasFormat("application/x-atticonhotel")) {
  84. qDebug() << "### dragEnterEvent si ";
  85. event->acceptProposedAction();
  86. } else {
  87. event->ignore();
  88. }
  89. }
  90.  
  91. void dragMoveEvent(QDragMoveEvent *event)
  92. {
  93. qDebug() << "### dragMoveEvent ";
  94.  
  95. if (event->mimeData()->hasFormat("application/x-atticonhotel")) {
  96. qDebug() << "### dragMoveEvent si ";
  97. event->acceptProposedAction();
  98. } else {
  99. event->ignore();
  100. }
  101. }
  102. bool enableout;
  103. signals:
  104. void AppendList(TabIcone);
  105. public slots:
  106.  
  107. };
To copy to clipboard, switch view to plain text mode