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
Creating a Dialog GUI To create a custom dialog with Qt Designer, select the appropriate template for the dialog from the New Form dialog. Drag and drop the required widgets onto the form, lay out them correctly, and save the form in a . ui file for later use in your application.
Qt Designer UI files represent the widget tree of the form in XML format. The forms can be processed: At compile time, which means that forms are converted to C++ code that can be compiled.
You generally don't need to promote the root element of UI tree. If you properly initialize your class using UI file, you can redefine closeEvent
without it. This answer shows how to do it properly.
I know this is old. I somehow ran into the same problem. I want to use docking features in a sub window. When I tried to promote the QMinWindow, I don't see it in the list. Then I tried using QWidget in the drop down list, it magically went through.
Just my experience.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With