QMdiArea Class

The QMdiArea widget provides an area in which MDI windows are displayed. More...

Header: #include <QMdiArea>
qmake: QT += widgets
Since: Qt 4.3
Inherits: QAbstractScrollArea

This class was introduced in Qt 4.3.

Public Types

enum AreaOption { DontMaximizeSubWindowOnActivation }
enum ViewMode { SubWindowView, TabbedView }
enum WindowOrder { CreationOrder, StackingOrder, ActivationHistoryOrder }

Properties

Public Functions

QMdiArea::WindowOrder activationOrder() const
QBrush background() const
bool documentMode() const
void setActivationOrder(QMdiArea::WindowOrder order)
void setBackground(const QBrush &background)
void setDocumentMode(bool enabled)
void setTabPosition(QTabWidget::TabPosition position)
void setTabShape(QTabWidget::TabShape shape)
void setTabsClosable(bool closable)
void setTabsMovable(bool movable)
void setViewMode(QMdiArea::ViewMode mode)
QTabWidget::TabPosition tabPosition() const
QTabWidget::TabShape tabShape() const
bool tabsClosable() const
bool tabsMovable() const
QMdiArea::ViewMode viewMode() const

Detailed Description

QMdiArea functions, essentially, like a window manager for MDI windows. For instance, it draws the windows it manages on itself and arranges them in a cascading or tile pattern. QMdiArea is commonly used as the center widget in a QMainWindow to create MDI applications, but can also be placed in any layout. The following code adds an area to a main window:

     QMainWindow *mainWindow = new QMainWindow;
     mainWindow->setCentralWidget(mdiArea);

Unlike the window managers for top-level windows, all window flags (Qt::WindowFlags) are supported by QMdiArea as long as the flags are supported by the current widget style. If a specific flag is not supported by the style (e.g., the WindowShadeButtonHint), you can still shade the window with showShaded().

Subwindows in QMdiArea are instances of QMdiSubWindow. They are added to an MDI area with addSubWindow(). It is common to pass a QWidget, which is set as the internal widget, to this function, but it is also possible to pass a QMdiSubWindow directly.The class inherits QWidget, and you can use the same API as with a normal top-level window when programming. QMdiSubWindow also has behavior that is specific to MDI windows. See the QMdiSubWindow class description for more details.

A subwindow becomes active when it gets the keyboard focus, or when setFocus() is called. The user activates a window by moving focus in the usual ways. The MDI area emits the subWindowActivated() signal when the active window changes, and the activeSubWindow() function returns the active subwindow.

The convenience function subWindowList() returns a list of all subwindows. This information could be used in a popup menu containing a list of windows, for example.

The subwindows are sorted by the current WindowOrder. This is used for the subWindowList() and for activateNextSubWindow() and activatePreviousSubWindow(). Also, it is used when cascading or tiling the windows with cascadeSubWindows() and tileSubWindows().

QMdiArea provides two built-in layout strategies for subwindows: cascadeSubWindows() and tileSubWindows(). Both are slots and are easily connected to menu entries.

Note: The default scroll bar property for QMdiArea is Qt::ScrollBarAlwaysOff.

See also QMdiSubWindow.

Member Type Documentation

enum QMdiArea::AreaOption

This enum describes options that customize the behavior of the QMdiArea.

ConstantValueDescription
QMdiArea::DontMaximizeSubWindowOnActivation0x1When the active subwindow is maximized, the default behavior is to maximize the next subwindow that is activated. Set this option if you do not want this behavior.

enum QMdiArea::ViewMode

This enum describes the view mode of the area; i.e. how sub-windows will be displayed.

ConstantValueDescription
QMdiArea::SubWindowView0Display sub-windows with window frames (default).
QMdiArea::TabbedView1Display sub-windows with tabs in a tab bar.

This enum was introduced or modified in Qt 4.4.

See also setViewMode().

enum QMdiArea::WindowOrder

Specifies the criteria to use for ordering the list of child windows returned by subWindowList(). The functions cascadeSubWindows() and tileSubWindows() follow this order when arranging the windows.

ConstantValueDescription
QMdiArea::CreationOrder0The windows are returned in the order of their creation.
QMdiArea::StackingOrder1The windows are returned in the order in which they are stacked, with the top-most window being last in the list.
QMdiArea::ActivationHistoryOrder2The windows are returned in the order in which they were activated.

See also subWindowList().

Property Documentation

activationOrder : WindowOrder

This property holds the ordering criteria for subwindow lists

This property specifies the ordering criteria for the list of subwindows returned by subWindowList(). By default, it is the window creation order.

This property was introduced in Qt 4.4.

Access functions:

QMdiArea::WindowOrder activationOrder() const
void setActivationOrder(QMdiArea::WindowOrder order)

See also subWindowList().

background : QBrush

This property holds the background brush for the workspace

This property sets the background brush for the workspace area itself. By default, it is a gray color, but can be any brush (e.g., colors, gradients or pixmaps).

Access functions:

QBrush background() const
void setBackground(const QBrush &background)

documentMode : bool

This property holds whether the tab bar is set to document mode in tabbed view mode.

Document mode is disabled by default.

This property was introduced in Qt 4.5.

Access functions:

bool documentMode() const
void setDocumentMode(bool enabled)

See also QTabBar::documentMode and setViewMode().

tabPosition : QTabWidget::TabPosition

This property holds the position of the tabs in tabbed view mode.

Possible values for this property are described by the QTabWidget::TabPosition enum.

This property was introduced in Qt 4.4.

Access functions:

QTabWidget::TabPosition tabPosition() const
void setTabPosition(QTabWidget::TabPosition position)

See also QTabWidget::TabPosition and setViewMode().

tabShape : QTabWidget::TabShape

This property holds the shape of the tabs in tabbed view mode.

Possible values for this property are QTabWidget::Rounded (default) or QTabWidget::Triangular.

This property was introduced in Qt 4.4.

Access functions:

QTabWidget::TabShape tabShape() const
void setTabShape(QTabWidget::TabShape shape)

See also QTabWidget::TabShape and setViewMode().

tabsClosable : bool

This property holds whether the tab bar should place close buttons on each tab in tabbed view mode.

Tabs are not closable by default.

This property was introduced in Qt 4.8.

Access functions:

bool tabsClosable() const
void setTabsClosable(bool closable)

See also QTabBar::tabsClosable and setViewMode().

tabsMovable : bool

This property holds whether the user can move the tabs within the tabbar area in tabbed view mode.

Tabs are not movable by default.

This property was introduced in Qt 4.8.

Access functions:

bool tabsMovable() const
void setTabsMovable(bool movable)

See also QTabBar::movable and setViewMode().

viewMode : ViewMode

This property holds the way sub-windows are displayed in the QMdiArea.

By default, the SubWindowView is used to display sub-windows.

This property was introduced in Qt 4.4.

Access functions:

QMdiArea::ViewMode viewMode() const
void setViewMode(QMdiArea::ViewMode mode)

See also ViewMode, setTabShape(), and setTabPosition().