我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用PyQt5.QtCore.Qt.Key_Delete()。
def keyPressEvent(self, event): if event.key() == Qt.Key_Delete: #event.accept() if self.lastItemClicked is not None: delkey = None for key in self.connections: if self.connections[key][1].workerTreeItem == self.lastItemClicked: delkey = key if delkey is not None: indx = self.workerDockWidget.workerTree.indexOfTopLevelItem(self.connections[delkey][1].workerTreeItem) self.workerDockWidget.workerTree.takeTopLevelItem(indx) self.connections[delkey][1].connection = None self.connections[delkey][0].callback = None del self.connections[delkey] return 1 return 0
def keyPressEvent(self, event): if event.key() == Qt.Key_Delete: #event.accept() if self.lastItemClicked is not None: delsheet = None for sheet in self.sheets: if sheet.treeitem == self.lastItemClicked: delsheet = sheet if delsheet is not None: indx = self.sheetWidget.sheetTree.indexOfTopLevelItem(sheet.treeitem) self.sheetWidget.sheetTree.takeTopLevelItem(indx) self.currentSheet = None self.sheetView.scene.clear() self.sheets.remove(delsheet) return 1 return 0
def keyPressEvent(self, event): pressedkey = event.key() if ((pressedkey == Qt.Key_Up or pressedkey == Qt.Key_Down) and int(app.keyboardModifiers()) == Qt.NoModifier): super(CommentListView, self).keyPressEvent(event) elif pressedkey == Qt.Key_Delete: deleteSelection() event.accept() elif pressedkey == Qt.Key_Enter or pressedkey == Qt.Key_Return: editSelection() event.accept() elif pressedkey == Qt.Key_C and int(app.keyboardModifiers()) == Qt.CTRL: copySelection() event.accept() else: event.ignore()
def keyPressEvent(self, event): if True:# not event.isAccepted(): if event.key() == Qt.Key_Delete: event.accept() # Delete selection except for init and loop nodes = [x for x in self.scene.items() if isinstance(x, Node)] for node in nodes: if node.isSelected() and not node == self.initnode and not node == self.loopnode: node.delete() self.scene.removeItem(node) found = True
def keyPressEvent(self, event: QKeyEvent): if event.key() == Qt.Key_Delete: # Delete selected rows rows = [i.row() for i in self.selectedIndexes()] for row in sorted(rows, reverse=True): self.model().remove_label_at(row) else: event.accept()
def keyPressEvent(self, event: QKeyEvent): if event.key() == Qt.Key_Delete: self.deletion_wanted.emit() event.ignore() else: super().keyPressEvent(event)
def keyPressEvent(self, event: QKeyEvent): if event.key() == Qt.Key_Delete: selected = self.selectionModel().selection() """:type: QtGui.QItemSelection """ if selected.isEmpty(): return min_row = numpy.min([rng.top() for rng in selected]) max_row = numpy.max([rng.bottom() for rng in selected]) self.deletion_wanted.emit(min_row, max_row) else: super().keyPressEvent(event)
def eventFilter(self, sender, event): if event.type() == QEvent.ChildRemoved: self.internalMove.emit() elif event.type() == QEvent.KeyPress and (event.key() == Qt.Key_Delete or event.key() == Qt.Key_Backspace): item = self.currentRow() item_name = self.currentItem().text() self.active_element_text = item_name self.takeItem(item) self.deleteElement.emit() return False
def set_text_spinbox(item, value=""): # useful for qtests. for i in range(3): QTest.keyPress(item, Qt.Key_Backspace) QTest.keyPress(item, Qt.Key_Delete) QTest.keyClicks(item, str(value)) QTest.keyPress(item, Qt.Key_Return)
def createActions(self): self.cell_sumAction = QAction("Sum", self) self.cell_sumAction.triggered.connect(self.actionSum) self.cell_addAction = QAction("&Add", self) self.cell_addAction.setShortcut(Qt.CTRL | Qt.Key_Plus) self.cell_addAction.triggered.connect(self.actionAdd) self.cell_subAction = QAction("&Subtract", self) self.cell_subAction.setShortcut(Qt.CTRL | Qt.Key_Minus) self.cell_subAction.triggered.connect(self.actionSubtract) self.cell_mulAction = QAction("&Multiply", self) self.cell_mulAction.setShortcut(Qt.CTRL | Qt.Key_multiply) self.cell_mulAction.triggered.connect(self.actionMultiply) self.cell_divAction = QAction("&Divide", self) self.cell_divAction.setShortcut(Qt.CTRL | Qt.Key_division) self.cell_divAction.triggered.connect(self.actionDivide) self.fontAction = QAction("Font...", self) self.fontAction.setShortcut(Qt.CTRL | Qt.Key_F) self.fontAction.triggered.connect(self.selectFont) self.colorAction = QAction(QIcon(QPixmap(16, 16)), "Background &Color...", self) self.colorAction.triggered.connect(self.selectColor) self.clearAction = QAction("Clear", self) self.clearAction.setShortcut(Qt.Key_Delete) self.clearAction.triggered.connect(self.clear) self.aboutSpreadSheet = QAction("About Spreadsheet", self) self.aboutSpreadSheet.triggered.connect(self.showAbout) self.exitAction = QAction("E&xit", self) self.exitAction.setShortcut(QKeySequence.Quit) self.exitAction.triggered.connect(QApplication.instance().quit) self.printAction = QAction("&Print", self) self.printAction.setShortcut(QKeySequence.Print) self.printAction.triggered.connect(self.print_) self.firstSeparator = QAction(self) self.firstSeparator.setSeparator(True) self.secondSeparator = QAction(self) self.secondSeparator.setSeparator(True)
def test_generator_label(self): labels = self.cframe.proto_analyzer.protocol_labels self.assertEqual(len(labels), 2) # Open Protocol in Generator self.form.ui.tabWidget.setCurrentIndex(2) item = self.gframe.tree_model.rootItem.children[0].children[0] index = self.gframe.tree_model.createIndex(0, 0, item) rect = self.gframe.ui.treeProtocols.visualRect(index) self.assertEqual(len(self.gframe.ui.treeProtocols.selectedIndexes()), 0) QTest.mousePress(self.gframe.ui.treeProtocols.viewport(), Qt.LeftButton, pos=rect.center()) self.assertEqual(self.gframe.ui.treeProtocols.selectedIndexes()[0], index) mimedata = self.gframe.tree_model.mimeData(self.gframe.ui.treeProtocols.selectedIndexes()) self.gframe.table_model.dropMimeData(mimedata, 1, -1, -1, self.gframe.table_model.createIndex(0, 0)) self.assertEqual(self.gframe.table_model.row_count, 3) # Check Label in Generator labels = self.gframe.table_model.protocol.protocol_labels self.assertEqual(len(labels), 2) # Fuzz Label lbl = copy.deepcopy(self.gframe.table_model.protocol.messages[0].message_type[1]) self.gframe.table_model.protocol.messages[0].message_type[1] = lbl lbl.fuzz_values.append("1") lbl.add_fuzz_value() lbl.add_fuzz_value() lbl.add_fuzz_value() lbl.add_fuzz_value() lbl.fuzz_me = Qt.Checked self.assertEqual(len(lbl.fuzz_values), 5) self.gframe.refresh_label_list() self.gframe.refresh_table() self.gframe.ui.btnFuzz.setEnabled(True) self.gframe.ui.btnFuzz.click() self.assertTrue(lbl.active_fuzzing) self.assertIn(lbl, self.gframe.table_model.protocol.messages[0].message_type) self.assertEqual(self.gframe.table_model.row_count, 4 + 3) # Check if Background for fuzzed labels is drawn correctly self.__check_background_is_drawn(lbl, 43, 43) # Delete a line old_row_count = self.gframe.table_model.row_count self.gframe.ui.tableMessages.selectRow(2) QTest.keyClick(self.gframe.ui.tableMessages, Qt.Key_Delete) self.assertEqual(self.gframe.table_model.row_count, old_row_count - 1) self.__check_background_is_drawn(lbl, 43, 43) # Remove everything for i in range(old_row_count): self.gframe.ui.tableMessages.selectRow(0) QTest.keyClick(self.gframe.ui.tableMessages, Qt.Key_Delete) self.assertEqual(self.gframe.table_model.row_count, 0)