I’m revisiting PyQt6 after months of frustration with both Kivy and KivyMD.
Why do we need to (if at all) set the Central Widget for QMainWindow ? Is there an examples show use of.
Thanks
I’m revisiting PyQt6 after months of frustration with both Kivy and KivyMD.
Why do we need to (if at all) set the Central Widget for QMainWindow ? Is there an examples show use of.
Thanks
Hi @weave welcome to the forum.
The QMainWindow
is a special widget which comes bundled with a bunch of built-in capabilities, such as the dock widgets, toolbars, statusbars and menus. These are all handled through built-in layouts on the main window.
Because of this you can’t override the layout on a QMainWindow
object, like you can for other widgets (if you did, none of these things would work).
The setCentralWidget
sets a widget into the middle of the window layout, in a region set aside for the window content.
If you want to set a layout on the content in the main window, you can create a container widget using QWidget
and apply the layout to that.
So if I used a QWidget instead of QMainWindow than the setCentralWidget is not required ? I still need to setLayout for the form though…
Yep that’s correct, setCentralWidget
only applies to QMainWindow
.
The decision of whether you use QWidget
or QMainWindow
just comes down to whether you need the things QMainWindow
provides (menus, toolbars, docks, etc.)
If you build a UI using QWidget
then you can either (i) display that widget as a window using .show()
, or (ii) use that same widget as the central widget in a QMainWindow
.
There is really no difference to how you build the UI in either case, just whether you have the additional functionality around it.
Thanks Martin for the input !
Also as mentioned above I’ve wasted a huge amount of time dealing with Kivy and have gone back to my original application and I’m currently revamping it with the latest version of PyQt6.and Python.
This morning I decided to build an executable with a portion of my revamped app (it’s still a work in progress) and guess what…
It compiled clean the first time… after months of things being broke here and there with Kivy it works the first time !
Yahooo !