Regions and QDockWidgets

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

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 it is set, a QDockWidget can be undocked, resized, dragged to a different location, or docked to the same or to a different dock window region by the end user.

The QMainWindow correctly creates the slidable QSplitters between the central widget and the QDockWidgets. The two principal QMainWindow functions for managing the dock window 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.

DockWindows are very important in integrated development environments, because different tools or views are needed in different situations. Each view is a widget, and they can all be "plugged" into the main window quite easily with the docking mechanism as shown in Figure 11.8.

Figure 11.8. Dragged DockWindows

Like most KDE applications, kdbg, the stand-alone KDE debugger, makes use of DockWindows. kdbg has a source code window (central widget) and dockable views for things such as:

These widgets do not all need to be visible at the same time, so there is a View menu that lets you select or de-select all of the different views. QMainWindow::createPopupMenu() returns this menu, permitting you to add it to toolbars or other pull-down menus.

Views of a QStringList

Категории