Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
6.4.3
-
None
Description
Running PySide6==6.4.3, Python 3.11 on Windows 11/Debian 11.6.
Consider the following code;
from PySide6.QtWidgets import QApplication, QMainWindow from PySide6.QtCore import QEvent def customEvent(event): print("customEvent:", event) application = QApplication([]) # Instantiate QMainWindow directly. main_window = QMainWindow() # Replace customEvent method. main_window.customEvent = customEvent # Send a custom event. event = QEvent(QEvent.Type(QEvent.User + 1)) application.postEvent(main_window, event) main_window.show() application.exec()
A 'user'/custom event is send to a QMainWindow widget resulting in the QMainWindow::customEvent being called.
As can be seen the QMainWindow widget is instantiated directly.
Now instantiate the QMainWindow by loading a *.ui file;
from PySide6.QtWidgets import QApplication from PySide6.QtCore import QEvent from PySide6.QtUiTools import QUiLoader def customEvent(event): print("customEvent:", event) application = QApplication([]) # Instantiate QMainWindow by loading a ui file. main_window = QUiLoader().load("untitled.ui") # Replace customEvent method. main_window.customEvent = customEvent # Send a custom event. event = QEvent(QEvent.Type(QEvent.User + 1)) application.postEvent(main_window, event) main_window.show() application.exec()
Note that the only thing that changed is;
main_window = QMainWindow()
is replaced by;
main_window = QUiLoader().load("untitled.ui")
With this code customEvent is no longer called.