Python PyQt4.QtCore 模块,QMimeData() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用PyQt4.QtCore.QMimeData()

项目:Modular_Rigging_Thesis    作者:LoganKelly    | 项目源码 | 文件源码
def startDrag(self, event):
        # item is of type NodeListItem
        item = self.currentItem()
        # nodeData is the data (BaseNode type) that item was created with
        nodeData = nt.NodeTypes[item.dictKey]
        #nodeData = mayaNodesModule.MayaNodes[item.dictKey])

        i = id(nodeData)
        self.d[i] = nodeData
        pickleData = cPickle.dumps(i)

        data = QtCore.QByteArray.fromRawData(pickleData)

        mimeData = QtCore.QMimeData()
        mimeData.setData("application/x-imgname", data)

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)

        # Setting the icon that the mouse cursor displays
        icon = item.icon()
        pixmap = icon.pixmap(48, 48)
        drag.setPixmap(pixmap.scaled(pixmap.height()*.5, pixmap.width()*.5))
        # Actually starts the dragging
        drag.exec_()
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def createDragData(self):
        self.drag = QtGui.QDrag(self)
        data = QtCore.QMimeData()
        wave_len = self.selection[1] + 1 - self.selection[0]
        samples = self.current_data[self.selection[0] * 256 + self.offset:(self.selection[1] + 1) * 256 + self.offset]
        data.setData('audio/wavesamples', samples)
        data.setText(self.current_source)
        path = QtGui.QPainterPath()
        sampwidth_int = self.current_sampwidth_int / 2
        path.moveTo(0, sampwidth_int - audioop.getsample(samples, self.current_sampwidth, 0))
        for s in xrange(1, len(samples)/2):
            path.lineTo(s, sampwidth_int - audioop.getsample(samples, self.current_sampwidth, s))
        wave_size = self.main.wavetable_view.width() / 64
        pixmap = QtGui.QPixmap(wave_size * wave_len, 48)
        pixmap.fill(QtCore.Qt.transparent)
        qp = QtGui.QPainter(pixmap)
        qp.setRenderHints(qp.Antialiasing)
        qp.scale((wave_size * wave_len / path.boundingRect().width()), 48. / self.current_sampwidth_int)
        qp.drawPath(path)
        qp.end()
        self.drag.setPixmap(pixmap)
        self.drag.setMimeData(data)
        self.drag.exec_()
项目:PH5    作者:PIC-IRIS    | 项目源码 | 文件源码
def mousePressEvent(self, event):
        #print ('Mouse press...')
        hotSpot = event.pos()

        mimeData = QtCore.QMimeData()
        mimeData.setText(self.text())
        mimeData.setData('application/x-hotspot',
                         '%d %d' % (hotSpot.x(), hotSpot.y()))

        pixmap = QtGui.QPixmap(self.size())
        self.render(pixmap)

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.setPixmap(pixmap)
        drag.setHotSpot(hotSpot)

        dropAction = drag.exec_(QtCore.Qt.CopyAction | QtCore.Qt.MoveAction, QtCore.Qt.CopyAction)

        if dropAction == QtCore.Qt.MoveAction:
            self.close()
            self.update()
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def mimeData(self, idxs):
        mimedata = QtCore.QMimeData()
        for idx in idxs:
            if idx.isValid():
                txt = self.data(idx, QtCore.Qt.DisplayRole)
                mimedata.setData('component/name', txt)
        return mimedata
    #------------------------------------------------------------------------------------------------    

#========================================================================================================================
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def mimeData(self, indexes):
        """
        This function is called by QT each time a drag operation is
        initiated, to serialize the data associated with the
        dragged item. However, QT doesn't know how to serialize a Shape
        or a Layer, so it throws an error ... since we handle Drag & Drop
        internally, we don't need any serialization, so we subclass
        the function and return nothing (trick to avoid errors).
        """
        mimeData = QtCore.QMimeData()
        #mimeData.setData("application/x-qabstractitemmodeldatalist", "")
        mimeData.setData("application/x-qstandarditemmodeldatalist", "")

        return mimeData
项目:olive-gui    作者:dturevski    | 项目源码 | 文件源码
def mousePressEvent(self, e):
        Mainframe.sigWrapper.sigFocusOnPieces.emit()
        if e.buttons() != QtCore.Qt.LeftButton:
            # On right click
            # if the square is empty, add the selected piece
            # if the square is non-empty, remove it
            if Mainframe.model.board.board[self.id] is None:
                if Mainframe.selectedPiece is not None:
                    Mainframe.model.board.add(model.Piece(Mainframe.selectedPiece.name,
                                                          Mainframe.selectedPiece.color,
                                                          Mainframe.selectedPiece.specs),
                                              self.id)
                else:
                    return
            else:
                Mainframe.selectedPiece = Mainframe.model.board.board[self.id]
                Mainframe.model.board.drop(self.id)
            Mainframe.model.onBoardChanged()
            Mainframe.sigWrapper.sigModelChanged.emit()
            return
        if Mainframe.model.board.board[self.id] is None:
            return

        # ctrl-drag copies existing piece
        modifiers = QtGui.QApplication.keyboardModifiers()
        Mainframe.currentlyDragged = Mainframe.model.board.board[self.id]
        if not (modifiers & QtCore.Qt.ControlModifier):
            Mainframe.model.board.drop(self.id)
            Mainframe.model.onBoardChanged()
            Mainframe.sigWrapper.sigModelChanged.emit()

        mimeData = QtCore.QMimeData()
        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(e.pos() - self.rect().topLeft())
        dropAction = drag.start(QtCore.Qt.MoveAction)
        Mainframe.currentlyDragged = None
项目:olive-gui    作者:dturevski    | 项目源码 | 文件源码
def mousePressEvent(self, e):
        if self.piece is None:
            return
        if e.buttons() != QtCore.Qt.LeftButton:
            return

        Mainframe.currentlyDragged = self.piece
        mimeData = QtCore.QMimeData()
        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(e.pos() - self.rect().topLeft())
        dropAction = drag.start(QtCore.Qt.MoveAction)
        Mainframe.currentlyDragged = None
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def __init__(self):
        QtCore.QMimeData.__init__(self)
        self.referenceDataObject = None
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def hasFormat(self, mime):
        if mime == 'data/reference' and self.referenceDataObject:
            return True
        return QtCore.QMimeData.hasFormat(self, mime)