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

event passed to custom "showEvent" is a "QtCore.QEvent" instead of the expected "QtGui.QShowEvent"

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 6.7.0
    • PySide
    • None
    • macOS 14.3.1
      Python 3.10.13 from brew
      pip install PySide6==6.7.0
    • macOS, Windows

    Description

      Here is a small repro:

      import sys
      
      from PySide6 import QtWidgets
      
      
      class TestWidget(QtWidgets.QWidget):
          def __init__(self, parent=None):
              super().__init__(parent)
              self.showMaximized()
      
          def event(self, event):
              # custom event processing with fall-back
              return super().event(event)
      
          def showEvent(self, event):
              # custom showEvent processing with fall-back
              super().showEvent(event)
      
      
      if __name__ == "__main__":
          app = QtWidgets.QApplication([])
          widget = TestWidget()
          widget.show()
          sys.exit(app.exec()) 

      This code runs fine with PySide6<=6.6.3.1

      With Pyside6==6.7.0, it raises the following TypeError:

      Traceback (most recent call last):
        File "/Users/jbnoel/devel/avdiff/avdiff/test.py", line 23, in <module>
          widget = TestWidget()
        File "/Users/jbnoel/devel/avdiff/avdiff/test.py", line 10, in __init__
          self.showMaximized()
        File "/Users/jbnoel/devel/avdiff/avdiff/test.py", line 14, in event
          return super().event(event)
        File "/Users/jbnoel/devel/avdiff/avdiff/test.py", line 18, in showEvent
          super().showEvent(event)
      TypeError: 'PySide6.QtWidgets.QWidget.showEvent' called with wrong argument types:
        PySide6.QtWidgets.QWidget.showEvent(QEvent)
      Supported signatures:
        PySide6.QtWidgets.QWidget.showEvent(PySide6.QtGui.QShowEvent)
      

      3 workarounds to make the above code work:

      • remove custom def event(self, event):
      • remove custom def showEvent(self, event):
      • "Convert" the event with the following workaround:
        if event.type() == QtCore.QEvent.Show:
            event = QtGui.QShowEvent()
        

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              jbnoel Jean-Baptiste NOEL
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes