[PyQt] Code interpretation

Anshul Jain aj.phoenixter at gmail.com
Wed Mar 31 21:11:09 BST 2010


Hello,
I've found this code snippet in PyQt eample for drag and drop of images. Can
anyone plz help me out in understanding this code snippet. I am new to this.


child = self.childAt(event.pos())
        if not child:
            return

        pixmap = QtGui.QPixmap(child.pixmap())

        itemData = QtCore.QByteArray()
        dataStream = QtCore.QDataStream(itemData,
QtCore.QIODevice.WriteOnly)
        dataStream << pixmap << QtCore.QPoint(event.pos() - child.pos())

        mimeData = QtCore.QMimeData()
        mimeData.setData('application/x-dnditemdata', itemData)

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        drag.setHotSpot(event.pos() - child.pos())
        tempPixmap = QtGui.QPixmap(pixmap)
        painter = QtGui.QPainter()
        painter.begin(tempPixmap)
        painter.fillRect(pixmap.rect(), QtGui.QColor(127, 127, 127, 127))
        painter.end()


Also, what does 'x-dnditemdata' mean in the line:
event.mimeData().hasFormat('application/x-dnditemdata')
I'll be really grateful if someone can help me out with this.

Regrards
Anshul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100401/a4732b2e/attachment.html>


More information about the PyQt mailing list