You again seem to be dead set on misusing Qt widgets. The entire purpose of QMainWindow is that is provides a framework with a menubar, toolbar, status bar, optional docking windows, and a central area into which you put the main part of your UI. QMainWindow has been designed in such a way that -it- manages the layout of all these subcomponents so that when you dock or undock widgets, add toolbars, resize your app, or whatever, QMainWindow's layout manager will rearrange things so they just work the way you would expect them to.However. I get run time complains...but runs.
Use QMainWindow the way it is supposed to be used, don't keep trying to invent your own broken wheel.
By inserting something directly into QMainWindow's layout, you will probably break something which then causes QMainWindow to behave incorrectly when something about the child widget arrangement changes. Yes, it might run, but it won't work correctly.
You apparently don't understand that a widget can have only one parent. When you set your MDI area as the central widget, that makes its parent whatever the central widget uses to manage that central area. It is probably not the QMainWindow's layout. So when you set your MDI area as the central widget, and then add it to QMainWindow's layout, it removes it from being the central widget and makes its parent the QMainWindow itself.setCentralWidget( mdiarea );
this->layout()->addWidget(mdiarea);
NO. Design your entire application as if the central widget is the only part of the UI you have control of. If you want to use QMdiArea as a central widget, use it as the central widget and add all of the rest of your UI as QMdiSubWindow instances inside the QMdiArea, using the QMdiArea API. If you want to base your application around a QTabWidget as the central widget, make a custom QWidget for each page, and add them to the tab widget using the QTabWidget API. Same thing if you want to use QStackedWidget instead. Do not try to game the system by directly accessing subcomponents of these widget like layouts and manually adding things to them. You will almost certainly break what they are designed to manage. Just because you can access a subcomponent doesn't mean you should. These "manager" widgets have their own APIs for a reason.Would I use using both methods - one to initially add base class (setCentralWidget) and then adding more classes
using layout ?
No matter what type of central widget you decide to use, if your application is going to have multiple "views", then each of these "views" will almost certainly be some QWidget-based class that you add layouts and child widgets to before adding that widget as a child of whatever manager you are using as a central widget (A QMdiSubWindow of a QMdiArea, a tab of a QTabWidget, or a child of a QStackedWidget, or something else).
Your application is a hierarchy of widgets, QMainWidget at the top, the central (manager) widget below that, and all of your custom widgets as children of that.
Bookmarks