View Full Version : centralWidget and QDockWidgets in designer

18th December 2006, 10:54
I am going through the designer manual provided with Qt-4.2.x. This is the first time I am trying to design userinterfaces with designer. I exclusively used code to achieve this in the past. Now, I've come across a little problem with designer. When coding, I would instantiate a QWidget object and set it as the centralWidget using QMainWindow::setCentralWidget() ... Then I would define the other elements and lay them out on this centralWidget, using whatever Layout is appropriate. Adding QDockWidgets was equally simple using QMainWindow::addDockWidget(). The defined centralWidget would automatically expand to take up the space between the menu- and Statusbar. Now with designer, the centralWidget is predefined and there is no way, I can directly access it. If I add widgets to the MainWindow Form, the widgets do not automatically take up the space reserved for the centralWidget, even though they are clearly marked as children of the centralWidget in the object inspector.

That can be easily solved when applying a layout to the form itself. This probably means that the layout is not applied to the QMainWindow (which would be wrong anyway, since QMainWindows already have a Layout ... ) but to the centralWidget. So far so good. But when I try to drag QDockWidgets onto the form, they are placed WITHIN the centralWidget as opposed to being added to the QMainWindow itself. to put it differently, I am looking for the Drag & Drop equivalent of QMainWindow::addDockWidget() ... .Any hints?

Thanx in advance

18th December 2006, 11:56
Try adding the dock widget by the time when the top level layout has not yet been set. Otherwise the dock widget seems to end up into the layout. Change the dock widget's properties (docked, dockWidgetArea) after dropping it on the form (docked property comes visible only when the dock widget is not in a layout and dockWidgetArea property comes visible after setting the docked property to true).

About the central widget, Designer handles it like you suspect. The central widget is created automatically and the top level layout is set on the central widget.