Subclass PyQt

The usual way to use Qt widgets from Python is to subclass them.

There are a lot of methods in the classes of the Qt widget, so I will inevitably add a method to a subclass with the same name as the one inherited from the Qt widget. In Python, all methods are virtual, so what worries me is that some Qt code may end up calling my method instead of the expected Qt-one - in the worst case, crack some extreme case that doesn't just show in testing.

On the other hand, it is possible that all PyQt methods are just wrappers for C ++ code, which, of course, will not be affected by anything that I do from the point of view of the Python subclass.

Does anyone know what it is?

+4
source share
1 answer

If the underlying C ++ methods are virtual, your Python methods that override them will be called at any time when the C ++ code calls them. If they are just regular methods, any C ++ code will call the original C ++ methods by default (Python code will call Python methods, though, since it sees the Python object and all methods are "virtual" there).

+3
source

All Articles