PyQT5之override覆盖槽函数


from PyQt5.QtCore import *
from PyQt5 import QtCore
from PyQt5.QtWidgets import *
import sys


class OverrideSlot(QMainWindow):

    def __init__(self):
        super().__init__()
        self.setWindowTitle("Override覆盖槽函数")

    def keyPressEvent(self, event):
        if event.key() == Qt.Key_Escape:   # 按下Esc关闭
            self.close()
        elif event.key() == Qt.Key_Alt:
            self.setWindowTitle("按下Alt键")


if __name__ == '__main__':

    app = QApplication(sys.argv)
    main_win = OverrideSlot()
    main_win.show()
    sys.exit(app.exec_())


posted @ 2024-06-08 15:45  星空28  阅读(8)  评论(0编辑  收藏  举报