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)
python类Key_F()的实例源码
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 __init__(self, parent=None):
QWidget.__init__(self, parent)
self.tape = []
self.tape_pos = -1
self.style_sheet = None
self.search_bar = QLineEdit(self)
self.search_bar.textChanged.connect(self.onSearchTextChanged)
self.style_text_edit = QTextEdit(self)
self.style_text_edit.textChanged.connect(self.onStyleTextChanged)
# To prevent messing with contents when pasted from an IDE, for
# instance.
self.style_text_edit.setAcceptRichText(False)
self.apply_button = QPushButton('Apply', self)
self.apply_button.clicked.connect(self.onApplyButton)
layout = QVBoxLayout(self)
layout.addWidget(self.search_bar)
layout.addWidget(self.style_text_edit)
layout.addWidget(self.apply_button)
self.setLayout(layout)
next_hit_shortcut = QShortcut(QKeySequence(Qt.Key_F3), self)
next_hit_shortcut.activated.connect(self.onNextSearchHit)
search_shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F), self)
search_shortcut.activated.connect(self.onFocusSearchBar)
apply_shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_S), self)
apply_shortcut.activated.connect(self.applyStyleSheet)
undo_shortcut = QShortcut(
QKeySequence(Qt.CTRL + Qt.ALT + Qt.Key_Z), self)
undo_shortcut.activated.connect(self.onUndo)
redo_shortcut = QShortcut(
QKeySequence(Qt.CTRL + Qt.ALT + Qt.Key_Y), self)
redo_shortcut.activated.connect(self.onRedo)
help_shortcut = QShortcut(
QKeySequence(Qt.Key_F1), self)
help_shortcut.activated.connect(self.onHelp)
self.loadStyleSheet()
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 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 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)