Python PyQt5.QtGui 模块,QKeyEvent() 实例源码

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

项目:Enibar    作者:ENIB    | 项目源码 | 文件源码
def event(self, event):
        """ Rewrite the event loop. Used to handle the  \n key
            If the \n key is pressed, call self.validate_transaction.
        """
        if isinstance(event, QtGui.QKeyEvent):
            if event.type() == QtCore.QEvent.KeyPress:
                if event.key() == QtCore.Qt.Key_Return or\
                        event.key() == QtCore.Qt.Key_Enter:
                    self.validate_transaction()
                    return True
                elif event.key() == QtCore.Qt.Key_Escape:
                    self.reset_product_list()
                    return True
                if event.modifiers() == QtCore.Qt.ControlModifier:
                    if event.key() == QtCore.Qt.Key_Tab:
                        panels_nb = self.panels.count()
                        self.panels.setCurrentIndex((self.panels.currentIndex() + 1) % panels_nb)
                if event.modifiers() == QtCore.Qt.ShiftModifier | QtCore.Qt.ControlModifier:
                    if event.key() == QtCore.Qt.Key_Backtab:
                        panels_nb = self.panels.count()
                        self.panels.setCurrentIndex((self.panels.currentIndex() - 1) % panels_nb)

        return super().event(event)
项目:Enibar    作者:ENIB    | 项目源码 | 文件源码
def test_add_note_categories(self):
        self.win.add_note_category_input.setText("test1")
        self.app.sendEvent(self.win.add_note_category_input, QtGui.QKeyEvent(QtGui.QKeyEvent.KeyPress, QtCore.Qt.Key_Return, QtCore.Qt.NoModifier))

        self.assertEqual(self.win.add_note_category_input.text(), "")
        self.assertEqual(self.get_items(self.win.shown_note_categories_list), ['test1'])
        self.assertEqual(self.get_items(self.win.hidden_note_categories_list), [])

        self.win.add_note_category_input.setText("test2")
        self.win.add_note_category_button.click()

        self.assertEqual(self.win.add_note_category_input.text(), "")
        self.assertEqual(self.get_items(self.win.shown_note_categories_list), ['test1', 'test2'])
        self.assertEqual(self.get_items(self.win.hidden_note_categories_list), [])

        self.win.add_note_category_input.setText("test2")

        def verif():
            win = self.app.activeWindow()
            self.assertIsInstance(win, QtWidgets.QMessageBox)
            win.accept()
        QtCore.QTimer.singleShot(200, verif)
        self.win.add_note_category_button.click()
项目:gpvdm    作者:roderickmackenzie    | 项目源码 | 文件源码
def keyPressEvent(self, event):

            if type(event) == QtGui.QKeyEvent:
                if event.text()=="f":
                    self.showFullScreen()
                if event.text()=="r":
                    if self.timer==None:
                        self.start_rotate()
                    else:
                        self.timer.stop()
                        self.timer=None
                if event.text()=="z":
                    if self.timer==None:
                        self.start_rotate()
                        if self.viewpoint.zoom>-40:
                            self.viewpoint.zoom =-400
                        self.timer=QTimer()
                        self.timer.timeout.connect(self.fzoom_timer)
                        self.timer.start(50)
                    else:
                        self.timer.stop()
                        self.timer=None
项目:tvlinker    作者:ozmartian    | 项目源码 | 文件源码
def keyPressEvent(self, event: QKeyEvent) -> None:
        if event.key() in (Qt.Key_Enter, Qt.Key_Return):
            return
        super(Settings, self).keyPressEvent(event)
项目:vidcutter    作者:ozmartian    | 项目源码 | 文件源码
def keyPressEvent(self, event: QKeyEvent) -> None:
        qApp.sendEvent(self.parent, event)
项目:vidcutter    作者:ozmartian    | 项目源码 | 文件源码
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)
项目:thegame    作者:afg984    | 项目源码 | 文件源码
def keyPressEvent(self, event: QKeyEvent):
        key = event.key()
        if key in self.keys:
            self.keys[key] = True
项目:thegame    作者:afg984    | 项目源码 | 文件源码
def keyReleaseEvent(self, event: QKeyEvent):
        if event.isAutoRepeat():
            event.ignore()
            return
        key = event.key()
        if key in self.keys:
            self.keys[key] = False
项目:Enibar    作者:ENIB    | 项目源码 | 文件源码
def event(self, event):
        """ Rewrite the event loop. Used to handle the  \n key
            If the \n key is pressed, call self.penrent.validate_transaction.
        """
        if isinstance(event, QtGui.QKeyEvent):
            if event.type() == QtCore.QEvent.KeyPress:
                if event.key() == QtCore.Qt.Key_Return or event.key() == QtCore.Qt.Key_Enter:
                    self.parent().validate_transaction()
                    return True
        return super().event(event)
项目:vivisect-py3    作者:bat-serjo    | 项目源码 | 文件源码
def keyPressEvent(self, ev: QtGui.QKeyEvent):
        ev.ignore()
项目:vivisect-py3    作者:bat-serjo    | 项目源码 | 文件源码
def keyReleaseEvent(self, ev: QtGui.QKeyEvent):
        ev.ignore()
项目:pyqt5    作者:yurisnm    | 项目源码 | 文件源码
def key_released(self):

        self.setStyleSheet(self.__style)
        if self.__str_key == "&&":
            self.__str_key = "&"
        event = QKeyEvent(QEvent.KeyPress, self.__key, Qt.NoModifier,
                          self.__str_key, False)
        QCoreApplication.postEvent(self.__receiver, event)
项目:pyqt5    作者:yurisnm    | 项目源码 | 文件源码
def keyPressEvent(self, evt):
        event = QKeyEvent(QEvent.KeyPress, evt.key(), evt.modifiers(),
                          evt.text(), False)
        QCoreApplication.postEvent(self.__receiver, event)
        evt.ignore()
项目:ciba    作者:FindHao    | 项目源码 | 文件源码
def keyPressEvent(self, e):
        keyEvent = QKeyEvent(e)
        ctrl = e.modifiers() & Qt.ControlModifier
        shift = e.modifiers() & Qt.ShiftModifier
        if keyEvent.key() == QtCore.Qt.Key_Escape:
            self.hide()
        # ctrl+c ??????????ctrl+shift+c?????????
        elif ctrl and keyEvent.key() == QtCore.Qt.Key_C:
            self.clipboard.setText(self.query.word.text)
        elif ctrl and keyEvent.key() == QtCore.Qt.Key_C and shift:
            self.clipboard.setText(self.query.word.raw_text)
项目:RTT-Console    作者:dudulung    | 项目源码 | 文件源码
def keyPressEvent(self, event):
        if type(event) != QtGui.QKeyEvent:
            return super().keyPressEvent(event)

        try:
            #print(event.text())
            self.key_pressed_cache.append(ord(event.text()))
            if event.text() == "\r":
                self.signal_key.emit(self.key_pressed_cache)
                self.key_pressed_cache = bytearray()
        except Exception as e:
            if event.key() == QtCore.Qt.Key_Question:
                self.key_pressed_cache.append(0x3F)

        return super().keyPressEvent(event)
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def keyPressEvent(self, event: QKeyEvent):
        if event.key() == Qt.Key_Delete:
            # Delete selected rows
            rows = [i.row() for i in self.selectedIndexes()]
            for row in sorted(rows, reverse=True):
                self.model().remove_label_at(row)
        else:
            event.accept()
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def keyPressEvent(self, event: QKeyEvent):
        if event.key() in (Qt.Key_Enter, Qt.Key_Return):
            selected = [index.row() for index in self.selectedIndexes()]
            if len(selected) > 0:
                self.edit_on_item_triggered.emit(min(selected))
        else:
            super().keyPressEvent(event)
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def keyPressEvent(self, event: QKeyEvent):
        if event.key() == Qt.Key_Shift:
            self.shift_mode = True

            if self.hold_shift_to_drag:
                self.setCursor(Qt.OpenHandCursor)
            else:
                self.unsetCursor()
                self.grab_start = None

        super().keyPressEvent(event)
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def keyReleaseEvent(self, event: QKeyEvent):
        if event.key() == Qt.Key_Shift:
            self.shift_mode = False

            if self.hold_shift_to_drag:
                self.unsetCursor()
                self.grab_start = None
            else:
                self.setCursor(Qt.OpenHandCursor)

        super().keyPressEvent(event)
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def keyPressEvent(self, event: QKeyEvent):
        if event.key() == Qt.Key_Delete:
            self.deletion_wanted.emit()
            event.ignore()
        else:
            super().keyPressEvent(event)
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def keyPressEvent(self, event: QKeyEvent):
        if event.key() == Qt.Key_Enter:
            event.ignore()
        else:
            event.accept()
项目:urh    作者:jopohl    | 项目源码 | 文件源码
def keyPressEvent(self, event: QKeyEvent):
        if event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return:
            return
        else:
            super().keyPressEvent(event)
项目:vidcutter    作者:ozmartian    | 项目源码 | 文件源码
def keyPressEvent(self, event: QKeyEvent) -> None:
        if self.mediaAvailable:

            if event.key() == Qt.Key_Space:
                self.playMedia()
                return

            if event.key() in {Qt.Key_F, Qt.Key_Escape}:
                self.mpvWidget.keyPressEvent(event)
                return

            if event.key() == Qt.Key_Home:
                self.setPosition(self.seekSlider.minimum())
                return

            if event.key() == Qt.Key_End:
                self.setPosition(self.seekSlider.maximum())
                return

            if event.key() == Qt.Key_Left:
                self.mpvWidget.frameBackStep()
                self.playAction.setVisible(True)
                self.pauseAction.setVisible(False)
                return

            if event.key() == Qt.Key_Down:
                if qApp.queryKeyboardModifiers() == Qt.ShiftModifier:
                    self.mpvWidget.seek(-self.level2Seek, 'relative+exact')
                else:
                    self.mpvWidget.seek(-self.level1Seek, 'relative+exact')
                return

            if event.key() == Qt.Key_Right:
                self.mpvWidget.frameStep()
                self.playAction.setVisible(True)
                self.pauseAction.setVisible(False)
                return

            if event.key() == Qt.Key_Up:
                if qApp.queryKeyboardModifiers() == Qt.ShiftModifier:
                    self.mpvWidget.seek(self.level2Seek, 'relative+exact')
                else:
                    self.mpvWidget.seek(self.level1Seek, 'relative+exact')
                return

            if event.key() in {Qt.Key_Return, Qt.Key_Enter} and \
                    (not self.timeCounter.hasFocus() and not self.frameCounter.hasFocus()):
                if self.cutStartAction.isEnabled():
                    self.clipStart()
                elif self.cutEndAction.isEnabled():
                    self.clipEnd()
                return