我们从Python开源项目中,提取了以下30个代码示例,用于说明如何使用PyQt5.QtCore.Qt.Key_Escape()。
def eventFilter(self, obj, ev): if (obj == self.m_button): k = ev.type() if k in [QEvent.KeyPress, QEvent.KeyRelease]:# Prevent the QToolButton from handling Enter/Escape meant control the delegate x = ev.key() if x in [Qt.Key_Escape, Qt.Key_Enter, Qt.Key_Return]: ev.ignore() return True return super(QtColorEditWidget, self).eventFilter(obj, ev)
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 keyPressEvent(self, qkeyevent): super(SearchBar, self).keyPressEvent(qkeyevent) if qkeyevent.key() == Qt.Key_Escape: self.setVisible(False) self.show_search_bar_button.setChecked(False)
def keyPressEvent(self, qkeyevent): super(FilterBar.Filter, self).keyPressEvent(qkeyevent) if qkeyevent.key() == Qt.Key_Escape: self.on_remove(self)
def keyPressEvent(self, event): if event.key() == Qt.Key_Escape and self._flashing: event.ignore()
def eventFilter(self, obj, ev): if (obj == self.m_button): k = ev.type() if k in [QEvent.KeyPress, QEvent.KeyRelease]:# Prevent the QToolButton from handling Enter/Escape meant control the delegate x = ev.key() if x in [Qt.Key_Escape, Qt.Key_Enter, Qt.Key_Return]: ev.ignore() return True return super(QtFontEditWidget, self).eventFilter(obj, ev)
def __init__(self): # Fucking QMainWindow calls a general super().__init__ on every parent class, don't call them here ! flags = Qt.WindowTitleHint | Qt.WindowSystemMenuHint | Qt.WindowCloseButtonHint flags = flags | Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint self.helpers = {} QMainWindow.__init__( self, flags=flags ) self.resize(1024, 768) self.tabs = TabWidget() layout = VLayout( [ self.tabs ] ) layout.setContentsMargins(10, 10, 10, 10) window = Widget() window.setLayout(layout) self.setCentralWidget(window) self.setWindowIcon(QIcon(constant.DEFAULT_ICON)) self.exit_shortcut = Shortcut(QKeySequence(Qt.Key_Escape), self, self.exit) self.setWindowTitle( '{} v{} - {}'.format(constant.APP_SHORT_NAME, __version__, constant.APP_RELEASE_NAME))
def keyPressEvent(self, event): "press ESCAPE to quit the application" key = event.key() if key == Qt.Key_Escape: self.app.quit()
def keyPressEvent(self, event: QKeyEvent) -> None: if event.key() in {Qt.Key_F, Qt.Key_Escape}: event.accept() if self.isFullScreen(): self._exitFullScreen() self.parent.toggleFullscreen() elif self.isFullScreen(): self.parent.keyPressEvent(event) else: super(mpvWidget, self).keyPressEvent(event)
def keyPressEvent(self, e): if e.key() == Qt.Key_Escape: self.close() if e.key() == Qt.Key_Return or e.key() == Qt.Key_Enter: self._sign_button_press()
def keyPressEvent(self,e): '''Close the window if escape is pressed, otherwise do as inherited.''' if e.key() == Qt.Key_Escape: self.close() else: QtGui.QMainWindow.keyPressEvent(self,e)
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 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)
def keyPressEvent(self, event): if event.key() == Qt.Key_Escape: QApplication.quit() elif event.key() == Qt.Key_F1: s = "" s += "\nAdapt: " s += ["on", "off"][Colors.noAdapt] s += "\nAdaption occured: " s += ["no", "yes"][Colors.adapted] w = QWidget() s += "\nColor bit depth: %d" % w.depth() s += "\nWanted FPS: %d" % Colors.fps s += "\nBenchmarked FPS: "; if Colors.benchmarkFps != -1: s += "%d" % Colors.benchmarkFps else: s += "not calculated" s += "\nAnimations: "; s += ["on", "off"][Colors.noAnimations] s += "\nBlending: "; s += ["on", "off"][Colors.useEightBitPalette] s += "\nTicker: "; s += ["on", "off"][Colors.noTicker] s += "\nPixmaps: "; s += ["off", "on"][Colors.usePixmaps] s += "\nRescale images on resize: "; s += ["on", "off"][Colors.noRescale] s += "\nTimer based updates: "; s += ["on", "off"][Colors.noTimerUpdate] s += "\nSeparate loop: "; s += ["no", "yes"][Colors.useLoop] s += "\nScreen sync: "; s += ["yes", "no"][Colors.noScreenSync] QMessageBox.information(None, "Current configuration", s) super(MainWindow, self).keyPressEvent(event)
def keyPressEvent(self, e): if e.key() == Qt.Key_Escape: if self.finder.hasFocus(): self.view1.setFocus() else: self.finder.setFocus()
def keyPressEvent(self, e): if e.key() == Qt.Key_Escape: self.close()
def keyPressEvent(self, QKeyEvent): if QKeyEvent.key() == Qt.Key_Escape: pass
def keyPressEvent(self, QKeyEvent): if QKeyEvent.key() == Qt.Key_Escape: pass if QKeyEvent.key() == Qt.Key_Enter or QKeyEvent.key() == Qt.Key_Return: self.slot_login()
def keyPressEvent(self, event): """ Prevent the user from closing the dialog using the ESC key. """ if event.key() == Qt.Key_Escape: event.ignore() else: QDialog.keyPressEvent(self, event)
def keyPressEvent(self, event): if event.key() == Qt.Key_Escape and self.isFullScreen(): self.setFullScreen(False) event.accept() elif event.key() == Qt.Key_Enter and event.modifiers() & Qt.Key_Alt: self.setFullScreen(not self.isFullScreen()) event.accept() else: super(VideoWidget, self).keyPressEvent(event)
def test_presseing_esc_does_not_close_or_clear_the_closable_graph(self): dummytitle = uniquestring() title = uniquestring() self.dummy = CurveDialogWithClosable(wintitle=dummytitle, mainwindow=self.aw) self.aw.addSubWindow(self.dummy) self.graph = CurveDialogWithClosable(wintitle=title, mainwindow=self.aw) self.graph.setClosable(False) self.aw.addSubWindow(self.graph) self.aw.show() self.assertTrue(self.graph.isVisible()) QTest.keyPress(self.graph, Qt.Key_Escape) self.assertTrue(self.graph.isVisible())
def test_presseing_esc_does_not_close_or_clear_the_data_window(self): dw = self.aw.datawindow self.aw.show() self.assertTrue(dw.isVisible()) QTest.keyPress(dw, Qt.Key_Escape) self.assertTrue(dw.isVisible()) self.aw.hide()
def keyPressEvent(self, event): """Keyboard press event Press a key on keyboard, the function will get an event, if the condition is met, call the function run_action(). In camera calibration mode, Effective key: W,A,S,D, ?, ?, ?, ?, ESC In front wheel calibration mode, Effective key: A, D, ?, ?, ESC In back wheel calibration mode, Effective key: A, D, ?, ?, ESC Args: event, this argument will get when an event of keyboard pressed occured """ key_press = event.key() if key_press in (Qt.Key_Up, Qt.Key_W): # UP if self.calibration_status == 1: cali_action('camcaliup') elif self.calibration_status == 2: pass elif self.calibration_status == 3: pass elif key_press in (Qt.Key_Right, Qt.Key_D): # RIGHT if self.calibration_status == 1: cali_action('camcaliright') elif self.calibration_status == 2: cali_action('fwcaliright') elif self.calibration_status == 3: cali_action('bwcaliright') elif key_press in (Qt.Key_Down, Qt.Key_S): # DOWN if self.calibration_status == 1: cali_action('camcalidown') elif self.calibration_status == 2: pass elif self.calibration_status == 3: pass elif key_press in (Qt.Key_Left, Qt.Key_A): # LEFT if self.calibration_status == 1: cali_action('camcalileft') elif self.calibration_status == 2: cali_action('fwcalileft') elif self.calibration_status == 3: cali_action('bwcalileft') cali_action('forward') elif key_press == Qt.Key_Escape: # ESC run_action('stop') self.close()