Question

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

Qt widget classes have a great many methods, so inevitably I'm going to end up adding a method to the subclass, with the same name as one inherited from the Qt widget. In Python, all methods are virtual, so what I'm concerned about is that some Qt code might end up calling my method instead of the expected Qt one - in the worst-case scenario, breaking some edge case that doesn't easily show up in testing.

On the other hand, maybe all the PyQt methods are just wrappers for C++ code, which would of course be unaffected by anything I do in terms of Python subclassing.

Anyone know offhand which is the case?

Was it helpful?

Solution

If the underlaying C++ methods are virtual, your Python methods that override them will be called any time 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 the Python methods though, because it sees the Python object and all methods are "virtual" there).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top