本文主要是了解視窗事件被觸發的相關時機。
先給一段程式碼:
""" 程式名稱:form_event.py 程式功能: 1. 視窗事件被觸發的相關時機 """ import sys from PySide6.QtGui import QFocusEvent from PySide6.QtWidgets import ( QWidget, QApplication) class MyApp(QWidget): def __init__(self): super().__init__() self.setWindowTitle('form_event.py') self.setGeometry(400, 250, 500, 300) self.show() def changeEvent(self, event): print('changeEvent') def closeEvent(self, event): print('closeEvent') def hideEvent(self, event): print('hideEvent') def moveEvent(self, event): print('moveEvent') def resizeEvent(self, event): print('resizeEvent') def showEvent(self, event): print('showEvent') if __name__ == '__main__': app = QApplication() my_app = MyApp() sys.exit(app.exec())
函式名稱 | 何時觸發 |
changeEvent |
|
closeEvent |
|
hideEvent |
|
moveEvent |
|
paintEvent |
|
resizeEvent |
|
showEvent |
|