How to drag images from Chrome to PyQt?
Question: I want to drag a picture from the browser but can not get the URL!

    
    
    if ev.mimeData().hasUrls():
        ev.mimeData().urls()
    

This code works well with images from Firefox(but I sometimes get the link of
the image not the source URL of the image - I already have an idea how to fix
it).

However, the same code returns an empty list when I drag a image from Chrome.

So, what's the problem?

* * *

I have tried draging image to default `QlineEdit` widget, and the src url was
dropped automaticly both FireFox and Chrome !

————

**Experimental result :**

    
    
    PyQt4 - Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 (Ubuntu 14.04)
    
    Firefox 32.0                          : Only work with URL, I can't found image type.
    Google chrome Version 37.0.2062.120 (64-bit) : URL is empty and no images founded.
    
    PyQt5 Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux2 (Ubuntu14.04)
    the same
    


Answer: All data drag & drop in `QWidget` (in PyQt) it must be common MIME types
([`QtCore.QMimeData`](http://pyqt.sourceforge.net/Docs/PyQt4/qmimedata.html)).
It's possibility data are not URL (`text/uri-list`) as in your problem, It
maybe MIME see image (`image/ *`) type only, not see URL (But sometime it see
both URL and image). But, your can get image data from `QtCore.QMimeData`
directly;

Your can try it, use method [`bool QMimeData.hasImage
(self)`](http://pyqt.sourceforge.net/Docs/PyQt4/qmimedata.html#hasImage) to
check type is image. And put image to `QImage` by call [`QVariant
QMimeData.imageData
(self)`](http://pyqt.sourceforge.net/Docs/PyQt4/qmimedata.html#imageData), see
example how to implement;

    
    
    import sys
    from PyQt4 import QtGui
    
    class QCustomQWidget (QtGui.QWidget):
        def __init__ (self, parentQWidget = None):
            super(QCustomQWidget, self).__init__(parentQWidget)
            self.mimeQLabel = QtGui.QLabel()
            allQHBoxLayout = QtGui.QHBoxLayout()
            allQHBoxLayout.addWidget(self.mimeQLabel)
            self.setLayout(allQHBoxLayout)
            self.setAcceptDrops(True)
    
        def dragEnterEvent (self, eventQDragEnterEvent):
            eventQDragEnterEvent.acceptProposedAction()
    
        def dropEvent (self, eventQDropEvent):
            self.mimeQLabel.clear()
            if eventQDropEvent.mimeData().hasImage():
                mimeQImage = QtGui.QImage(eventQDropEvent.mimeData().imageData())
                self.mimeQLabel.setPixmap(QtGui.QPixmap.fromImage(mimeQImage))
            elif eventQDropEvent.mimeData().hasUrls():
                self.mimeQLabel.setText('\n'.join([str(url) for url in eventQDropEvent.mimeData().urls()]))
            QtGui.QWidget.dropEvent(self, eventQDropEvent)
    
    app = QtGui.QApplication(sys.argv)
    myQCustomQWidget = QCustomQWidget()
    myQCustomQWidget.show()
    sys.exit(app.exec_())
    

* * *

**Experimental result :**

    
    
    PyQt4 - Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
    
    Firefox 31.0                          : Image & URL work fine.
    Google chrome Version 37.0.2062.103 m : Only work with URL, I can't found image type.
    

