Hello,

I'm currently trying to implement a drag'n'drop feature in a small program I'm developing.

The feature is partially working, the item can be dragged from a widget to another, but as the drag begin, the QPixmap associated with it is completely black.

Here's exactly what happens :

GIFrecord_2015-04-28_160010.gif

And here's the code where I start the drag event :

Qt Code:
  1. void ActionButtonWidget::mouseMoveEvent(QMouseEvent * event)
  2. {
  3. QDrag *drag = new QDrag(this);
  4. QMimeData *mimeData = new QMimeData;
  5. QByteArray itemData;
  6. QDataStream dataStream(&itemData, QIODevice::WriteOnly);
  7. dataStream << * this;
  8. mimeData->setData("customWidget/actionButton",itemData);
  9. drag->setMimeData(mimeData);
  10. drag->setPixmap(QPixmap(*(this->pixmap()))); //This should be getting the pixmap from my widget right ?
  11. drag->setHotSpot(QPoint(drag->pixmap().width()/2,
  12. drag->pixmap().height()));
  13. Qt::DropAction dropAction = drag->exec();
  14. }
To copy to clipboard, switch view to plain text mode 

I don't understand why I can't get the result I want, I've even tried to load an external picture into the my QDrag pixmap, but the result is the same, always a black square.

Does anybody have a clue on why it is behaving like this ?

Thank you in advance for your answers !

Regards,

Azsde.