Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-31113

CLONE - QMimeData does not provide image/png if the imagedrag is in-process

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • 5.1.0 Beta 1
    • GUI: Drag and Drop
    • None
    • Checked on Win and Linux, reproducible on the both. Probably on Mac as well.
    • macOS

      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:

      #include <QtCore>
      #include <QtGui>
      #include <QtWidgets>
      
      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("mail-message.png");
              Q_ASSERT(!img.isNull());
              mimeData->setImageData(img);
              drag->setPixmap(QPixmap::fromImage(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();
      }
      
      

        1. mail-message.png
          0.4 kB
          Gatis Paeglis
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Unassigned Unassigned
            paeglis Gatis Paeglis
            Veli-Pekka Heinonen Veli-Pekka Heinonen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes