I already created a second window for my application in the Qt Designer. I read that a QMainWindow would be the wrong class for the second window (which basically should only be some kind of dialog), so I would like to change the base class.
My Question(s) are:
The QObject class is the base class of all Qt objects. QObject is the heart of the Qt object model providing support for signals, slots, and the meta object system. The QPaintDevice class is the base class of objects that can be painted on with QPainter.
In Designer, activate the centralWidget and assign a layout, e.g. horizontal or vertical layout. Then your QFormLayout will automatically resize. Always make sure, that all widgets have a layout! Otherwise, automatic resizing will break with that widget!
The QWidget class is the base class of all user interface objects.
To change the base class you could only change the : public QMainWindow
to : public QWidget
(or vice-versa) in the header-file and of course also the *.cpp.
Basically all three are QWidgets, each with special functionality or for specific purposes. As far as I know the QMainWindow has toolbars, menubars and docks, a QDialog will always be shown as a seperate window (e.g. blocking, non-blocking, etc.) and the QWidget itself is the base-class. I.e. QPushButton, QCombobox are derived from QWidget too. In my opinion it would be better to use only one QMainWindow since it should be a central point of interaction/navigation for the user
EDIT: I forgot to mention that also the UI-file has to be changed, i.e. by using a text-editor, change the line (4th row I think)
<widget class="QMainWindow" name="YourClassName">
to
<widget class="QWidget" name"YourClassName">
and remove all QMainWindows related parts (menubar, toolbar, ...), and the enclosing tag for the central widget.
Thanks to alexisdm for the tip.
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