我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用PyQt5.QtCore.Qt.Key_Space()。
def keyPressEvent(self, event): if event.key() in [Qt.Key_Return, Qt.Key_Enter, Qt.Key_Space]:## Trigger Edit if (not self.m_editorPrivate.editedItem()): item = self.currentItem() if item: if (item.columnCount() >= 2 and ((item.flags() & (Qt.ItemIsEditable | Qt.ItemIsEnabled)) == (Qt.ItemIsEditable | Qt.ItemIsEnabled))): event.accept() ## If the current position is at column 0, move to 1. index = self.currentIndex() if (index.column() == 0): index = index.sibling(index.row(), 1) self.setCurrentIndex(index) self.edit(index) return super(QtPropertyEditorView, self).keyPressEvent(event)
def keyPressEvent(self, event): key = event.key() text = self.text() if key == Qt.Key_Space: if text and not text.endswith('-'): self.setText(text + '-') elif key == Qt.Key_Tab: if text and len(text.split('-')) < 3 and not text.endswith('-'): self.setText(text + '-') else: self.setText(text) elif key == Qt.Key_Escape: if text: self.parent.reset() else: self.parent.close() else: return QLineEdit.keyPressEvent(self, event)
def set_up_keyboard_symbols_keys(self): row_1 = [Qt.Key_BracketLeft, Qt.Key_BracketRight, Qt.Key_BraceLeft, Qt.Key_BraceRight, Qt.Key_Aring, Qt.Key_Percent, Qt.Key_Dead_Circumflex, Qt.Key_Asterisk, Qt.Key_Plus, Qt.Key_Equal, Qt.Key_Backspace] row_2 = [Qt.Key_Underscore, Qt.Key_Backslash, Qt.Key_Aring, Qt.Key_Dead_Tilde, Qt.Key_Less, Qt.Key_Greater, Qt.Key_Aring, Qt.Key_Aring, Qt.Key_Aring, Qt.Key_Return] row_3 = [Qt.Key_Aring, Qt.Key_Period, Qt.Key_Comma, Qt.Key_Question, Qt.Key_Exclam, Qt.Key_QuoteLeft, Qt.Key_QuoteDbl, Qt.Key_Aring] row_4 = [Qt.Key_Aring, Qt.Key_Space, Qt.Key_Aring, Qt.Key_Aring] self.keyboard_symbols_keys = [row_1, row_2, row_3, row_4]
def keyPressEvent(self, event): if not self.isStarted or self.isPaused or self.curPiece.shape() == NoShape: super(TetrixBoard, self).keyPressEvent(event) return key = event.key() if key == Qt.Key_Left: self.tryMove(self.curPiece, self.curX - 1, self.curY) elif key == Qt.Key_Right: self.tryMove(self.curPiece, self.curX + 1, self.curY) elif key == Qt.Key_Down: self.tryMove(self.curPiece.rotatedRight(), self.curX, self.curY) elif key == Qt.Key_Up: self.tryMove(self.curPiece.rotatedLeft(), self.curX, self.curY) elif key == Qt.Key_Space: self.dropDown() elif key == Qt.Key_D: self.oneLineDown() else: super(TetrixBoard, self).keyPressEvent(event)
def keyPressEvent(self, event): key_handlers = { Qt.Key_1: self.select_number(1), Qt.Key_2: self.select_number(2), Qt.Key_3: self.select_number(3), Qt.Key_4: self.select_number(4), Qt.Key_5: self.select_number(5), Qt.Key_6: self.select_number(6), Qt.Key_7: self.select_number(7), Qt.Key_8: self.select_number(8), Qt.Key_9: self.select_number(9), Qt.Key_0: self.select_number(0), Qt.Key_A: self.start_edit(self.goals.add, 'Add new goal'), Qt.Key_C: self.with_refresh(self.goals.toggle_close), Qt.Key_D: self.with_refresh(self.goals.delete), Qt.Key_I: self.start_edit(self.goals.insert, 'Insert new goal'), Qt.Key_L: self.with_refresh(self.goals.toggle_link), Qt.Key_Q: self.quit_app.emit, Qt.Key_R: self.start_edit(self.goals.rename, 'Rename goal'), Qt.Key_S: self.with_refresh(self.goals.swap_goals), Qt.Key_V: self.toggle_view, Qt.Key_Z: self.toggle_zoom, Qt.Key_Escape: self.cancel_edit, Qt.Key_Space: self.with_refresh(self.goals.hold_select), } if event.key() in key_handlers: key_handlers[event.key()]() else: super().keyPressEvent(event)
def set_up_keyboard_keys(self): row_1 = [Qt.Key_Q, Qt.Key_W, Qt.Key_E, Qt.Key_R, Qt.Key_T, Qt.Key_Y, Qt.Key_Y, Qt.Key_I, Qt.Key_O, Qt.Key_P, Qt.Key_Backspace] row_2 = [Qt.Key_A, Qt.Key_S, Qt.Key_D, Qt.Key_F, Qt.Key_G, Qt.Key_H, Qt.Key_J, Qt.Key_K, Qt.Key_L, Qt.Key_Ccedilla, Qt.Key_Return] row_3 = [Qt.Key_Aring, Qt.Key_Z, Qt.Key_X, Qt.Key_C, Qt.Key_V, Qt.Key_B, Qt.Key_N, Qt.Key_M, Qt.Key_Comma, Qt.Key_Period, Qt.Key_Question, Qt.Key_Aring] row_4 = [Qt.Key_Aring, Qt.Key_Space, Qt.Key_Left, Qt.Key_Right, Qt.Key_Aring] self.keyboard_keys = [row_1, row_2, row_3, row_4]
def set_up_keyboard_numbers_keys(self): row_1 = [Qt.Key_1, Qt.Key_2, Qt.Key_3, Qt.Key_4, Qt.Key_5, Qt.Key_6, Qt.Key_7, Qt.Key_8, Qt.Key_9, Qt.Key_0, Qt.Key_Backspace] row_2 = [Qt.Key_Minus, Qt.Key_Slash, Qt.Key_Colon, Qt.Key_Semicolon, Qt.Key_ParenLeft, Qt.Key_ParenRight, Qt.Key_Dollar, Qt.Key_Ampersand, Qt.Key_At, Qt.Key_Return] row_3 = [Qt.Key_Aring, Qt.Key_Period, Qt.Key_Comma, Qt.Key_Question, Qt.Key_Exclam, Qt.Key_QuoteLeft, Qt.Key_QuoteDbl, Qt.Key_Aring] row_4 = [Qt.Key_Aring, Qt.Key_Space, Qt.Key_Aring, Qt.Key_Aring] self.keyboard_numbers_keys = [row_1, row_2, row_3, row_4]
def keyPressEvent(self, event): if event.key() == Qt.Key_Escape and self.isFullScreen(): self.showNormal() if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_Q: self.close() sys.exit() if event.key() == Qt.Key_Space: if self.player.player.state() == self.player.player.PlayingState: self.player.pause() elif self.player.player.state() == self.player.player.StoppedState or self.player.player.PausedState: self.player.play() if event.key() == Qt.Key_Plus: self.player.setVolume(self.player.volume() + 5) if event.key() == Qt.Key_Minus: self.player.setVolume(self.player.volume() - 5) if event.modifiers() == Qt.ControlModifier and event.key() == Qt.Key_M: self.player.setMuted(not self.player.isMuted()) if event.key() == Qt.Key_Right: self.player.player.setPosition(self.player.player.position() + 10000) if event.key() == Qt.Key_Left: self.player.player.setPosition(self.player.player.position() - 10000) if event.key() == Qt.Key_Up: self.player.player.setPosition(self.player.player.position() + 60000) if event.key() == Qt.Key_Down: self.player.player.setPosition(self.player.player.position() - 60000) super().keyPressEvent(event)