Python PyQt5.QtCore.Qt 模块,Key_Down() 实例源码

我们从Python开源项目中,提取了以下19个代码示例,用于说明如何使用PyQt5.QtCore.Qt.Key_Down()

项目:mpvQC    作者:Frechdachs    | 项目源码 | 文件源码
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()
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
def keyReleaseEvent(self, event):

        if event.type() == QEvent.KeyRelease:

            if event.key() == Qt.Key_Up:
                current = max(0, self.current - 1)
                if 0 <= current < len(self.history):
                    self.setText(self.history[current])
                    self.current = current

                event.accept()

            elif event.key() == Qt.Key_Down:
                current = min(len(self.history), self.current + 1)
                if 0 <= current < len(self.history):
                    self.setText(self.history[current])
                else:
                    self.clear()
                self.current = current

                event.accept()
项目:Mac-Python-3.X    作者:L1nwatch    | 项目源码 | 文件源码
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)
项目:examples    作者:pyqt    | 项目源码 | 文件源码
def keyReleaseEvent(self, event):

        if event.type() == QEvent.KeyRelease:

            if event.key() == Qt.Key_Up:
                current = max(0, self.current - 1)
                if 0 <= current < len(self.history):
                    self.setText(self.history[current])
                    self.current = current

                event.accept()

            elif event.key() == Qt.Key_Down:
                current = min(len(self.history), self.current + 1)
                if 0 <= current < len(self.history):
                    self.setText(self.history[current])
                else:
                    self.clear()
                self.current = current

                event.accept()
项目:examples    作者:pyqt    | 项目源码 | 文件源码
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)
项目:headcache    作者:s9w    | 项目源码 | 文件源码
def keyPressEvent(self, ev):
        super().keyPressEvent(ev)

        # arrow keys are delegated to the result list
        if ev.key() in [Qt.Key_Up, Qt.Key_Down]:
            self.parent().parent().overlay.l1.keyPressEvent(ev)
            return

        elif ev.key() == Qt.Key_Return:
            self.parent().parent().goto_result()
            return

        # only search when query is long enough and different from last (not
        # just cursor changes)
        length_threshold = 2
        length_criteria = len(self.text()) >= length_threshold
        if self.text() != self.query_old and length_criteria:
            self.parent().parent().search_with(self.text())
        self.parent().parent().overlay.update_visibility(length_criteria)

        self.query_old = self.text()
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
def keyReleaseEvent(self, event):

        if event.type() == QEvent.KeyRelease:

            if event.key() == Qt.Key_Up:
                current = max(0, self.current - 1)
                if 0 <= current < len(self.history):
                    self.setText(self.history[current])
                    self.current = current

                event.accept()

            elif event.key() == Qt.Key_Down:
                current = min(len(self.history), self.current + 1)
                if 0 <= current < len(self.history):
                    self.setText(self.history[current])
                else:
                    self.clear()
                self.current = current

                event.accept()
项目:pyqt5-example    作者:guinslym    | 项目源码 | 文件源码
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)
项目:AlphaHooks    作者:AlphaHooks    | 项目源码 | 文件源码
def eventFilter(self, source, event):

        # Console Input
        if source is self.ui.console_input:
            if event.type() == QEvent.KeyPress:
                if event.key() in (Qt.Key_Enter, Qt.Key_Return):
                    command = self.ui.console_input.text()
                    if command != "":
                        readline.add_history(
                            command
                        )
                    self.length = readline.get_current_history_length()
                    self.index = -1

                if event.key() == Qt.Key_Up:
                    if self.index < self.length:
                        self.index += 1
                        command = readline.get_history_item(
                            self.length - self.index
                        )
                        self.ui.console_input.setText(
                            command
                        )

                if event.key() == Qt.Key_Down:
                    if self.index > 0:
                        self.index -= 1
                        command = readline.get_history_item(
                            self.length - self.index
                        )

                        self.ui.console_input.setText(
                            command
                        )

            return False
        return False
项目:cookiecutter-pyqt5    作者:mandeep    | 项目源码 | 文件源码
def test_open_file(window, qtbot, mock):
    """Test the Open File item of the File submenu.

    Qtbot clicks on the file sub menu and then navigates to the Open File item. Mock creates
    an object to be passed to the QFileDialog.
    """
    qtbot.mouseClick(window.file_sub_menu, Qt.LeftButton)
    qtbot.keyClick(window.file_sub_menu, Qt.Key_Down)
    mock.patch.object(QFileDialog, 'getOpenFileName', return_value=('', ''))
    qtbot.keyClick(window.file_sub_menu, Qt.Key_Enter)
项目:cookiecutter-pyqt5    作者:mandeep    | 项目源码 | 文件源码
def test_about_dialog(window, qtbot, mock):
    """Test the About item of the Help submenu.

    Qtbot clicks on the help sub menu and then navigates to the About item. Mock creates
    a QDialog object to be used for the test.
    """
    qtbot.mouseClick(window.help_sub_menu, Qt.LeftButton)
    qtbot.keyClick(window.help_sub_menu, Qt.Key_Down)
    mock.patch.object(QDialog, 'exec_', return_value='accept')
    qtbot.keyClick(window.help_sub_menu, Qt.Key_Enter)
项目:defconQt    作者:trufont    | 项目源码 | 文件源码
def keyPressEvent(self, event):
        key = event.key()
        modifiers = event.modifiers()
        if key in (Qt.Key_Up, Qt.Key_Down, Qt.Key_Left, Qt.Key_Right):
            self._arrowKeyPressEvent(event)
        elif key == Qt.Key_Return:
            index = self._lastSelectedCell
            if index is not None:
                self.glyphActivated.emit(self._glyphs[index])
        elif modifiers in (Qt.NoModifier, Qt.ShiftModifier):
            self._glyphNameInputEvent(event)
        else:
            super(GlyphCellWidget, self).keyPressEvent(event)
项目:defconQt    作者:trufont    | 项目源码 | 文件源码
def _arrowKeyPressEvent(self, event):
        count = event.count()
        key = event.key()
        modifiers = event.modifiers()
        # TODO: it might be the case that self._lastSelectedCell cannot be None
        # when we arrive here whatsoever
        if self._lastSelectedCell is not None:
            if key == Qt.Key_Up:
                delta = -self._columnCount
            elif key == Qt.Key_Down:
                delta = self._columnCount
            elif key == Qt.Key_Left:
                delta = -1
            elif key == Qt.Key_Right:
                delta = 1
            newSel = self._lastSelectedCell + delta * count
            if newSel < 0 or newSel >= len(self._glyphs):
                return
            if modifiers & Qt.ShiftModifier:
                self._selection |= self._linearSelection(newSel)
            else:
                self._selection = {newSel}
            self._lastSelectedCell = newSel
            self.scrollToCell(newSel)
            self.selectionChanged.emit()
            self.update()
项目:uitester    作者:IfengAutomation    | 项目源码 | 文件源码
def keyPressEvent(self, e):
        completion_prefix = self.text_under_cursor()
        if self.cmp and self.popup_widget.func_list_widget.isVisible():
            current_row = self.popup_widget.func_list_widget.currentRow()
            if e.key() == Qt.Key_Down:
                self.current_item_down(current_row)
                return

            if e.key() == Qt.Key_Up:
                self.current_item_up(current_row)
                return

            if e.key() in (Qt.Key_Return, Qt.Key_Enter):
                selected_word = self.popup_widget.func_list_widget.currentItem().text()
                self.insert_func_name_signal.emit(completion_prefix, selected_word)
                return

        if e.key() in (Qt.Key_Return, Qt.Key_Enter):
            self.parse_content()

        is_shortcut = ((e.modifiers() & Qt.ControlModifier) and e.key() == Qt.Key_E)  # shortcut key:ctrl + e
        if is_shortcut:
            self.cmp.update("", self.popup_widget)
            self.update_popup_widget_position()
            self.activateWindow()
            return

        if not self.cmp or not is_shortcut:
            super(TextEdit, self).keyPressEvent(e)
项目:pisi-player    作者:mthnzbk    | 项目源码 | 文件源码
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)
项目:SunFounder_PiCar-V    作者:sunfounder    | 项目源码 | 文件源码
def keyPressEvent(self, event):
        """Keyboard press event

        Effective key: W, A, S, D, ?,  ?,  ?,  ?
        Press a key on keyboard, the function will get an event, if the condition is met, call the function 
        run_action(). 

        Args:
            event, this argument will get when an event of keyboard pressed occured

        """
        key_press = event.key()

        # don't need autorepeat, while haven't released, just run once
        if not event.isAutoRepeat():
            if key_press == Qt.Key_Up:          # up 
                run_action('camup')
            elif key_press == Qt.Key_Right:     # right
                run_action('camright')
            elif key_press == Qt.Key_Down:      # down
                run_action('camdown')
            elif key_press == Qt.Key_Left:      # left
                run_action('camleft')
            elif key_press == Qt.Key_W:         # W
                run_action('forward')
            elif key_press == Qt.Key_A:         # A
                run_action('fwleft')
            elif key_press == Qt.Key_S:         # S
                run_action('backward')
            elif key_press == Qt.Key_D:         # D
                run_action('fwright')
项目:SunFounder_PiCar-V    作者:sunfounder    | 项目源码 | 文件源码
def keyReleaseEvent(self, event):
        """Keyboard released event

        Effective key: W,A,S,D, ?,  ?,  ?,  ?
        Release a key on keyboard, the function will get an event, if the condition is met, call the function 
        run_action(). 

        Args:
            event, this argument will get when an event of keyboard release occured

        """
        # don't need autorepeat, while haven't pressed, just run once
        key_release = event.key()
        if not event.isAutoRepeat():
            if key_release == Qt.Key_Up:        # up
                run_action('camready')
            elif key_release == Qt.Key_Right:   # right
                run_action('camready')
            elif key_release == Qt.Key_Down:    # down
                run_action('camready')
            elif key_release == Qt.Key_Left:    # left
                run_action('camready')
            elif key_release == Qt.Key_W:       # W
                run_action('stop')
            elif key_release == Qt.Key_A:       # A
                run_action('fwstraight')
            elif key_release == Qt.Key_S:       # S
                run_action('stop')
            elif key_release == Qt.Key_D:       # D
                run_action('fwstraight')
项目:uPyLoader    作者:BetaRavener    | 项目源码 | 文件源码
def eventFilter(self, target, event):
        def match(s1, s2):
            for x in s2:
                if s1.matches(x) == QKeySequence.ExactMatch:
                    return True
            return False

        if target == self.inputTextBox:
            if isinstance(event, QKeyEvent):
                if event.type() == QKeyEvent.KeyPress:
                    event_sequence = QtHelper.key_event_sequence(event)
                    if match(event_sequence, Settings().new_line_key):
                        return False
                    if match(event_sequence, Settings().send_key):
                        self.send_input()
                        return True
                    if event.key() == Qt.Key_Tab:
                        self.inputTextBox.insertPlainText(" "*Settings().terminal_tab_spaces)
                        return True
                    if event.key() == Qt.Key_Up and (event.modifiers() & Qt.ControlModifier):
                        if self._input_history_index > 0:
                            self._input_history_index -= 1
                            self.inputTextBox.clear()
                            self.inputTextBox.setPlainText(self.terminal.input(self._input_history_index))
                    if event.key() == Qt.Key_Down and (event.modifiers() & Qt.ControlModifier):
                        if self._input_history_index < self.terminal.last_input_idx():
                            self._input_history_index += 1
                            self.inputTextBox.clear()
                            self.inputTextBox.setPlainText(self.terminal.input(self._input_history_index))
        elif target == self.outputTextEdit:
            if isinstance(event, QKeyEvent):
                if event.type() == QEvent.KeyPress:
                    if event.key() == Qt.Key_Up:
                        self.connection.send_bytes(b"\x1b[A")
                    if event.key() == Qt.Key_Down:
                        self.connection.send_bytes(b"\x1b[B")
                    else:
                        t = event.text()
                        if t:
                            self.connection.send_character(t)
                    return True
        elif target == self.outputTextEdit.verticalScrollBar():
            if isinstance(event, QHideEvent):
                return True
        return False
项目:SunFounder_PiCar-V    作者:sunfounder    | 项目源码 | 文件源码
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()