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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1: Critical
    • Resolution: Done
    • Affects Version/s: 4.5.1
    • Fix Version/s: 4.8.0
    • Component/s: GUI: Drag and Drop
    • Labels:
      None
    • Commits:
      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();
      }
      

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            earthdomain Earth Domain (Inactive)
            Reporter:
            sanonymous Nokia Qt Support (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes