There is something I do not understand about Qt Designer
. I have been working with it for a while now, and still I always end up editing the .ui files manually.
As it can be seen in every single tutorial on Qt, one of the very first thing you do when you create a GUI is to subclass QMainWindow
- in order to catch and redefine the closeEvent()
function, for example.
However, it is not possible to subclass ("promote") QMainWindow
in Qt Designer - you can do it with many other class, but not this one.
What I usually do is edit the .ui file and change:
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
by:
< widget class="MyMainWindow" name="MainWindow">
So that my code can subclass QMainWindow
properly in my code:
class MyMainWindow(QMainWindow, object):
''' I can redefine closeEvent here! '''
Obviously, this is weird - and I probably miss something about the right way to do it with Designer. But I cannot find any explanation.
Why is it not possible to subclass QMainWindow
in Designer, or how to structure my application differently to avoid the need for it?
Thanks