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_())