QMainWindow::QMainWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()) Constructs a QMainWindow with the given parent and the specified widget flags. QMainWindow sets the Qt::Window flag itself, and will hence always be created as a top-level widget.
Add at least one widget on your MainWindow . Then select your window by clicking on it and click on the VerticalLayout Button at the top of QTCreator . You Vertical Layout is automatically added to the central widget and fills all the surface.
Qt Main Window Framework A main window provides a framework for building an application's user interface. Qt has QMainWindow and its related classes for main window management. QMainWindow has its own layout to which you can add QToolBar s, QDockWidget s, a QMenuBar , and a QStatusBar .
The centralwidget refers to a relative position but it is not exactly a central position: #include <QtWidgets> int main(int argc, char *argv[]) { QApplication a(argc, argv); QMainWindow w; QLabel *central_widget = new QLabel("Central Widget"); central_widget->setAlignment(Qt::AlignCenter); w.
We have a window with several components in QDockWidget
s. Ideally, we'd like to have all components dockable, but there is one component that will likely always be visible. So we made that the central widget.
However, this does not allow us to create a tabbed stack of dockable widgets (as you can create by e.g. calling tabifyDockWidget
) containing this central widget. So, we tried to create a UI without a central widget, but with several QDockWidget
s.
I cannot find any indication in the manual of QDockWidget
or QMainWindow
that this is a situation that isn't allowed. We create as much as possible in Qt Designer, and it seems to require that you have a central widget - as it shows by crashing after manually editing the XML.
The question is: is it legal to have a QMainWindow
with only QDockWidget
s and no central widget? Is Qt Designer just crashing because of a bug, or is it telling me that this is a bad idea and I need to stop doing this?
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