Skip to content
Advertisement

PyCharm showing wrong parameter info for PyQt methods

I don’t do a lot of work in GUI’s, but I’ve decided to move from occasionally using PyQt4 to PyQt5. My IDE is giving me warnings about some of the __init__ functions, particularly QWidget and QMainWindow.

If you look at the IntelliSense’d parameters, you’ll see that the parentparameter has a default and the flags does not. The IDE tells me that flags is unfilled, but when I don’t provide it, nothing happens. Why is this happening?

I’m using Python 3.5.

None

Advertisement

Answer

The correct signature is this:

QMainWindow(parent: QWidget = None,
            flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags())

So it looks like the IntelliSense in your IDE either does not know how to parse type-hints properly, or the PyQt stub files need to be installed. There are only two arguments: parent and flags, both of which have defaults.

(NB: you should never use self.__class__ with super as it can lead to an infinite recursion under certain circumstances. Always pass in the subclass as the first argument – unless you’re using Python 3, in which case you can omit all the arguments).

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement