Hi, as in the subject I started playing with drag and drop. The idea is to have a QListWidget filled with some items then dragging one item on the desktop (i'm using kde) it should create a plasmoid with the item's text. I prepared the plasmoid and added to .desktop the line X-Plasma-DropMimeTypes=text/plain. Next I coded the app: have created a new class subclassing QListWidget and redefined QStringList ListWidget::mimeTypes () to return "plain/text" as mime type.

Now, after compiling it, if i try to drag an item on the desktop correctly popupS a menu asking which plasmoid create (between mine and notes witdget) but, no matter what I choose, I got an empty plasmoid: no text is passed dragging.

Here the code:

header
Qt Code:
  1. #include <QtGui/QMainWindow>
  2. #include <QtGui/QListWidget>
  3.  
  4. class ListWidget : public QListWidget
  5. {
  6. Q_OBJECT
  7. public:
  8. ListWidget(QWidget *parent);
  9.  
  10. protected:
  11. QStringList mimeTypes () const;
  12. };
  13.  
  14. class PassMime : public QMainWindow
  15. {
  16. Q_OBJECT
  17. public:
  18. PassMime();
  19. virtual ~PassMime();
  20. QStringList i18n(const char* arg1);
  21. };
To copy to clipboard, switch view to plain text mode 

implementation
Qt Code:
  1. #include <QtGui/QLabel>
  2. #include <QtGui/QMenu>
  3. #include <QtGui/QMenuBar>
  4. #include <QtGui/QAction>
  5. #include <QtGui/QListWidget>
  6. #include <QtCore/QMimeData>
  7. #include <QtCore/QDebug>
  8.  
  9. ListWidget::ListWidget(QWidget* parent): QListWidget(parent)
  10. {
  11.  
  12. }
  13.  
  14. QStringList ListWidget::mimeTypes () const
  15. {
  16. list << "text/plain";
  17.  
  18. return list;
  19. }
  20.  
  21. PassMime::PassMime()
  22. {
  23. sl << "apple";
  24. sl << "orange";
  25. sl << "lemon";
  26.  
  27. ListWidget *l = new ListWidget(this);
  28. l->setDragEnabled(true);
  29. foreach(QString s, sl) {
  30. item->setText(s);
  31. l->addItem(item);
  32. }
  33.  
  34. setCentralWidget( l );
  35. QAction* a = new QAction(this);
  36. a->setText( "Quit" );
  37. connect(a, SIGNAL(triggered()), SLOT(close()) );
  38. menuBar()->addMenu( "File" )->addAction( a );
  39. }
  40.  
  41. PassMime::~PassMime()
  42. {}
To copy to clipboard, switch view to plain text mode 

I tried to override QMimeData * QListWidget::mimeData(const QList<QListWidgetItem *> items) with this new one:

Qt Code:
  1. QMimeData * ListWidget::mimeData(const QList<QListWidgetItem *> items)
  2. {
  3. QString text;
  4. foreach(QListWidgetItem *i, items) {
  5. text += i->text() + "\n";
  6. }
  7.  
  8. QMimeData *data = new QMimeData;
  9. data->setText(text);
  10.  
  11. return data;
  12. }
To copy to clipboard, switch view to plain text mode 

but probably I did it the wrong way since still doesn't work.

What I miss?

Cheers