Lv.的博客

PyQt5 键盘事件

from PyQt5.Qt import *
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("鼠标事件")
        self.resize(600,500)
        self.func_list()

    # 键盘事件
    # QKeyEvent
    def keyPressEvent(self,QKeyEvent):
        if QKeyEvent.key() == Qt.Key_5:
            print('QQQQQ')
        if QKeyEvent.modifiers() == Qt.ControlModifier and QKeyEvent.key() == Qt.Key_C:
            print('aaaaa')
        if QKeyEvent.modifiers() == Qt.ControlModifier | Qt.ShiftModifier and QKeyEvent.key() == Qt.Key_C:
            print('oooooo')

    def keyReleaseEvent(self,QKeyEvent):
        print('WWWWWWWWWWWW')

    def func_list(self):
        self.func()


    def func(self):
        pass

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()

    # window.setMouseTracking(True)

    window.show()
    sys.exit(app.exec_())

 

posted @ 2022-05-31 17:09  Avatarx  阅读(361)  评论(0编辑  收藏  举报