10.2.  Regions and QDockWidgets

[ fromfile: mainwindows.xml id: dockwindows ]

Any class that derives from QMainWindow has dock window regions, one on each of the four sides of the central widget, as shown in Figure 10.6. These regions are used for attaching secondary windows, also called dock windows, to the central widget.

Figure 10.6.  QMainWindow Regions

QMainWindow Regions

A QDockWidget can be thought of as an envelope for another widget. It has a title bar and a content area to contain the other widget. Depending on how its attributes are set, a QDockWidget can be undocked (so that it "floats"), resized, closed, dragged to a different location, or docked to the same or to a different dock widget region by the end user. It's okay to have several dockwidgets occupying the same dock region.

The QMainWindow correctly creates slidable QSplitters between the central widget and the QDockWidgets. The two principal QMainWindow functions for managing the dock widget regions are

  1. setCentralWidget(QWidget*), which establishes the central widget.

  2. addDockWidget(Qt::DockWidgetAreas, QDockWidget*), which adds the given QDockWidget to the specified dock window region.

Dock windows are important in integrated development environments because different tools or views are needed in different situations. Each dock window is a widget that can be "plugged" into the main window quite easily with the docking mechanism, as shown in Figure 10.7.

Figure 10.7.  Designer Floating QDockWindows

Designer Floating QDockWindows

Like most Qt applications, Designer, the tool for designing and building GUIs, makes heavy use of dock windows. Designer has a widget editor (central widget) and dockable views for tools such as

These dockables do not all need to be visible at the same time, so there is a View menu that enables you to select or deselect them as needed. QMainWindow::createPopupMenu() returns this menu, permitting you use it from context menus, or add it to toolbars or to pull-down menus.