我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用PyQt5.QtCore.QMimeData()。
def mousePressEvent(self, event): hotSpot = event.pos() mimeData = QMimeData() mimeData.setText(self.text()) mimeData.setData('application/x-hotspot', '%d %d' % (hotSpot.x(), hotSpot.y())) pixmap = QPixmap(self.size()) self.render(pixmap) drag = QDrag(self) drag.setMimeData(mimeData) drag.setPixmap(pixmap) drag.setHotSpot(hotSpot) dropAction = drag.exec_(Qt.CopyAction | Qt.MoveAction, Qt.CopyAction) if dropAction == Qt.MoveAction: self.close() self.update()
def mouseMoveEvent(self, e): if e.buttons() != Qt.RightButton: return mimeData = QMimeData() drag = QDrag(self) drag.setMimeData(mimeData) drag.setHotSpot(e.pos() - self.rect().topLeft()) dropAction = drag.exec_(Qt.MoveAction)
def mimeData(self, indexes): mimedata = QtCore.QMimeData() encoded_data = QtCore.QByteArray() stream = QtCore.QDataStream(encoded_data, QtCore.QIODevice.WriteOnly) for index in indexes: if index.isValid(): text = self.data(index, 0) stream << QtCore.QByteArray(text.encode('utf-8')) mimedata.setData('application/vnd.treeviewdragdrop.list', encoded_data) return mimedata
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
def pop(self, row, parent=QtCore.QModelIndex()): self.beginRemoveRows(parent, row, row + 1) self.rows.pop(row) self.endRemoveRows() # def mimeTypes(self): # types = QtCore.QStringList() # types.append('vqt/row') # return types # def mimeData(self, idx): # nodes = [ self.rows[i.row()][-1] for i in idx ] # mdata = QtCore.QMimeData() # mdata.setData('vqt/rows',json.dumps(nodes)) # return mdata
def mimeData(self, idxs): mdata = QMimeData() nodes = [] for idx in idxs: item = self.itemFromIndex(idx) if item: node = item.data(Qt.UserRole) if node: nodes.append(node.nodeid.to_string()) mdata.setText(", ".join(nodes)) return mdata
def mimeData(self, indexes): data = '' for index in indexes: parent_item = self.getItem(index.parent()) if parent_item == self.rootItem: data += "{0},{1},{2}/".format(index.row(), index.column(), -1) else: data += "{0},{1},{2}/".format(index.row(), index.column(), self.rootItem.index_of(parent_item)) mime_data = QMimeData() mime_data.setText(data) return mime_data
def mimeData(self, indexes): data = "PLabels:" data += "/".join([str(index.row()) for index in indexes]) mime_data = QMimeData() mime_data.setText(data) return mime_data
def mousePressEvent(self, event): if event.button() == Qt.LeftButton: self.drag_started.emit(self.mapToParent(event.pos())) drag = QDrag(self) mimeData = QMimeData() mimeData.setText("Move Signal") pixmap = QPixmap(self.rect().size()) self.render(pixmap, QPoint(), QRegion(self.rect())) drag.setPixmap(pixmap) drag.setMimeData(mimeData) drag.exec_()