def mouseMoveEvent(self, event): """ If the mouse moves far enough when the left mouse button is held down, start a drag and drop operation. """ if not event.buttons() & Qt.LeftButton: return if (event.pos() - self.dragStartPosition).manhattanLength() \ < QApplication.startDragDistance(): return if not self.hasImage: return drag = QDrag(self) mimeData = QMimeData() output = QByteArray() outputBuffer = QBuffer(output) outputBuffer.open(QIODevice.WriteOnly) self.imageLabel.pixmap().toImage().save(outputBuffer, 'PNG') outputBuffer.close() mimeData.setData('image/png', output) drag.setMimeData(mimeData) drag.setPixmap(self.imageLabel.pixmap().scaled(64, 64, Qt.KeepAspectRatio)) drag.setHotSpot(QPoint(drag.pixmap().width() / 2, drag.pixmap().height())) drag.start()
def mouseMoveEvent(self, event): """ If the mouse moves far enough when the left mouse button is held down, start a drag and drop operation. """ if not event.buttons() & Qt.LeftButton: return if (event.pos() - self.dragStartPosition).manhattanLength() \ < QApplication.startDragDistance(): return if not self.hasImage: return drag = QDrag(self) mimeData = QMimeData() output = QByteArray() outputBuffer = QBuffer(output) outputBuffer.open(QIODevice.WriteOnly) self.imageLabel.pixmap().toImage().save(outputBuffer, 'PNG') outputBuffer.close() mimeData.setData('image/png', output) drag.setMimeData(mimeData) drag.setPixmap(self.imageLabel.pixmap().scaled(64, 64, Qt.KeepAspectRatio)) drag.setHotSpot(QPoint(drag.pixmap().width() / 2, drag.pixmap().height())) drag.start()
def mousePressEvent(self, press_event): parent = self.parent() for item in parent.items: item.deselect() self.selected = True drag = QDrag(self) mime = QMimeData() print(self.item.w_data_item.action.module + "." + self.item.w_data_item.action_name) mime.setText(self.item.w_data_item.action.module + "." + self.item.w_data_item.action_name) drag.setMimeData(mime) drag.setPixmap(self.pixmap) drag.setHotSpot(QPoint( drag.pixmap().width()/2, drag.pixmap().height()/2)) ret = drag.exec(Qt.MoveAction)