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

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

项目:tahoe-gui    作者:LeastAuthority    | 项目源码 | 文件源码
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)
项目:defconQt    作者:trufont    | 项目源码 | 文件源码
def keyPressEvent(self, event):
        key = event.key()
        if key == Qt.Key_Return:
            cursor = self.textCursor()
            indentLvl = self.findLineIndentLevel()
            if self.openBlockDelimiter is not None:
                cursor.movePosition(QTextCursor.PreviousCharacter,
                                    QTextCursor.KeepAnchor)
                if cursor.selectedText() == self.openBlockDelimiter:
                    indentLvl += 1
            super(BaseCodeEditor, self).keyPressEvent(event)
            newLineSpace = "".join(self._indent for _ in range(indentLvl))
            cursor = self.textCursor()
            cursor.insertText(newLineSpace)
        elif key in (Qt.Key_Backspace, Qt.Key_Backtab):
            cursor = self.textCursor()
            if key == Qt.Key_Backtab and cursor.hasSelection():
                self.performLinewiseIndent(cursor, False)
            else:
                cursor.movePosition(QTextCursor.PreviousCharacter,
                                    QTextCursor.KeepAnchor,
                                    len(self._indent))
                if cursor.selectedText() == self._indent:
                    cursor.removeSelectedText()
                else:
                    super(BaseCodeEditor, self).keyPressEvent(event)
        elif key == Qt.Key_Tab:
            cursor = self.textCursor()
            if cursor.hasSelection():
                self.performLinewiseIndent(cursor)
            else:
                cursor.insertText(self._indent)
        else:
            super(BaseCodeEditor, self).keyPressEvent(event)

    # --------------
    # Other builtins
    # --------------
项目: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