Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
4.5.1
-
None
-
c319214f919e3345f673391253f92c6bc0e2a285
Description
When doing a drag-n-drop in-process, the qmimedata only has application/x-qt-image and none of the actual portable image formats, so this implementation fails.
When doing a drag-n-drop from one process to another (you can test this by running the program twice), everything works fine, image/png and all other image formats are in the qmimedata.
Can be reproduced with the following:
class MyWidget : public QLabel { public: MyWidget(): QLabel(0) { setMinimumSize(QSize(200, 200)); setAcceptDrops(true); } protected: virtual void dropEvent(QDropEvent* event) { const QMimeData* mimeData = event->mimeData(); qDebug() << "allFormats:" << mimeData->formats(); const QString mime = "image/png"; const QByteArray data = mimeData->data(mime); if(data.isEmpty()) { qWarning("Bug: image/png data is not available when the drag is from the same process!"); } QPixmap pix; if (!pix.loadFromData(data)) qWarning("loading failed"); setPixmap(pix); event->acceptProposedAction(); } virtual void dragEnterEvent(QDragEnterEvent* event) { event->accept(); } virtual void dragMoveEvent(QDragMoveEvent* event) { event->accept(); } virtual void mouseMoveEvent(QMouseEvent*) { QDrag* drag = new QDrag(this); QMimeData* mimeData = new QMimeData; mimeData->setText(text()); QImage img("image.png"); Q_ASSERT(!img.isNull()); mimeData->setImageData(img); drag->setMimeData(mimeData); drag->exec(); } }; int main( int argc, char ** argv ) { QApplication app(argc, argv); MyWidget w1; w1.setText("Please drag from this widget"); w1.show(); MyWidget w2; w2.setText("Drop here"); w2.show(); return app.exec(); }