我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用PyQt5.QtCore.Qt.CopyAction()。
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 dropEvent(self, event): """ Handle 'Drop' event. """ if event.mimeData().hasUrls(): B3App.Instance().setOverrideCursor(QCursor(Qt.ArrowCursor)) event.setDropAction(Qt.CopyAction) # multi-drag support for url in event.mimeData().urls(): path = url.path() if b3.getPlatform() == 'nt': # on win32 the absolute path returned for each url has a leading slash: this obviously # is not correct on win32 platform when absolute url have the form C:\\Programs\\... (Qt bug?) path = path.lstrip('/').lstrip('\\') if os.path.isfile(path): self.parent().parent().make_new_process(path) event.accept() else: event.ignore() ############################################ TOOLBAR HANDLERS ######################################################
def supportedDropActions(self): return Qt.CopyAction | Qt.MoveAction
def drag_handler(self, event: QDropEvent, drop: bool=False): if event.mimeData().hasUrls(): event.setDropAction(Qt.CopyAction) event.accept() if drop: self.files_dropped.emit([url.toLocalFile() for url in event.mimeData().urls()]) else: event.ignore()
def test_signal_view(self): self.add_signal_to_form("esaver.complex") signal = self.form.signal_tab_controller.signal_frames[0].signal tree_view = self.dialog.ui.treeViewSignals tree_model = tree_view.model() item = tree_model.rootItem.children[0].children[0] index = tree_model.createIndex(0, 0, item) rect = tree_view.visualRect(index) QTest.mousePress(tree_view.viewport(), Qt.LeftButton, pos=rect.center()) mime_data = tree_model.mimeData([index]) drag_drop = QDropEvent(rect.center(), Qt.CopyAction|Qt.MoveAction, mime_data, Qt.LeftButton, Qt.NoModifier) drag_drop.acceptProposedAction() self.dialog.ui.gVOriginalSignal.dropEvent(drag_drop) self.assertEqual(self.dialog.ui.gVOriginalSignal.sceneRect().width(), signal.num_samples) self.dialog.ui.cbShowDataBitsOnly.click() self.dialog.ui.chkBoxLockSIV.click() self.assertEqual(int(self.dialog.ui.gVOriginalSignal.view_rect().width()), int(self.dialog.ui.gVModulated.view_rect().width())) freq = self.dialog.ui.doubleSpinBoxCarrierFreq.value() self.dialog.ui.btnAutoDetect.click() self.assertNotEqual(freq, self.dialog.ui.doubleSpinBoxCarrierFreq.value()) self.dialog.ui.comboBoxModulationType.setCurrentText("Frequency Shift Keying (FSK)") self.dialog.ui.btnAutoDetect.click() self.assertEqual(self.dialog.ui.lCurrentSearchResult.text(), "1") self.dialog.ui.btnSearchNext.click() self.assertEqual(self.dialog.ui.lCurrentSearchResult.text(), "2") self.dialog.ui.btnSearchPrev.click() self.assertEqual(self.dialog.ui.lCurrentSearchResult.text(), "1")
def dragEnterEvent(self, event): """ Handle 'Drag Enter' event. """ if event.mimeData().hasUrls(): B3App.Instance().setOverrideCursor(QCursor(Qt.DragCopyCursor)) event.setDropAction(Qt.CopyAction) event.accept() else: event.ignore()