我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用PyQt5.QtCore.Qt.MoveAction()。
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 dropEvent(self, e): position = e.pos() self.button.move(position) e.setDropAction(Qt.MoveAction) e.accept()
def dragEnterEvent(self, event): if event.mimeData().hasText(): if event.source() in self.children(): event.setDropAction(Qt.MoveAction) event.accept() else: event.acceptProposedAction() else: event.ignore()
def dropEvent(self, event): if event.mimeData().hasText(): mime = event.mimeData() pieces = mime.text().split() position = event.pos() hotSpot = QPoint() hotSpotPos = mime.data('application/x-hotspot').split(' ') if len(hotSpotPos) == 2: hotSpot.setX(hotSpotPos[0].toInt()[0]) hotSpot.setY(hotSpotPos[1].toInt()[0]) for piece in pieces: newLabel = DragLabel(piece, self) newLabel.move(position - hotSpot) newLabel.show() position += QPoint(newLabel.width(), 0) if event.source() in self.children(): event.setDropAction(Qt.MoveAction) event.accept() else: event.acceptProposedAction() else: event.ignore()
def supportedDragActions(self): return Qt.MoveAction | Qt.CopyAction