Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2269

customEvent not called when *.ui file is used

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 6.4.3
    • PySide
    • None
    • Linux/X11, Windows

    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.
       

      Attachments

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            owillebo Okko Willeboordse
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: