|  | Home · All Classes · Main Classes · Grouped Classes · Modules · Functions |

# QMdiArea Class Reference
[QtGui module]

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

     #include <QMdiArea>

Inherits QAbstractScrollArea.

- List of all members, including inherited members

### Public Types

- enum AreaOption { DontMaximizeSubWindowOnActivation }
- flags AreaOptions
- enum WindowOrder { CreationOrder, StackingOrder }

### Properties

- background : QBrush
- scrollBarsEnabled : bool

- 2 properties inherited from QAbstractScrollArea
- 6 properties inherited from QFrame
- 56 properties inherited from QWidget
- 1 property inherited from QObject

### Public Functions

- QMdiArea ( QWidget * parent = 0 )
- ~QMdiArea ()
- QMdiSubWindow * activeSubWindow () const
- QMdiSubWindow * addSubWindow ( QWidget * widget, Qt::WindowFlags windowFlags = 0 )
- QBrush background () const
- void removeSubWindow ( QWidget * widget )
- bool scrollBarsEnabled () const
- void setBackground ( const QBrush & background )
- void setOption ( AreaOption option, bool on = true )
- void setScrollBarsEnabled ( bool enable )
- QList<QMdiSubWindow *> subWindowList ( WindowOrder order = CreationOrder ) const
- bool testOption ( AreaOption option ) const

- 15 public functions inherited from QAbstractScrollArea
- 13 public functions inherited from QFrame
- 200 public functions inherited from QWidget
- 29 public functions inherited from QObject
- 12 public functions inherited from QPaintDevice

### Public Slots

- void activateNextSubWindow ()
- void activatePreviousSubWindow ()
- void cascadeSubWindows ()
- void closeActiveSubWindow ()
- void closeAllSubWindows ()
- void setActiveSubWindow ( QMdiSubWindow * window )
- void tileSubWindows ()

- 19 public slots inherited from QWidget
- 1 public slot inherited from QObject

### Signals

- void subWindowActivated ( QMdiSubWindow * window )

- 1 signal inherited from QWidget
- 1 signal inherited from QObject

### Protected Slots

- void setupViewport ( QWidget * viewport )

- 1 protected slot inherited from QAbstractScrollArea
- 1 protected slot inherited from QWidget

### Additional Inherited Members

- 4 static public members inherited from QWidget
- 5 static public members inherited from QObject
- 16 protected functions inherited from QAbstractScrollArea
- 38 protected functions inherited from QWidget
- 7 protected functions inherited from QObject
- 1 protected function inherited from QPaintDevice

## Detailed Description

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

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 programmatically set the flag (e.g., by using QMdiSubWindow::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, for example by clicking a window or by pressing Tab. 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.

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

If you want your users to be able to work with child windows larger than the visible MDI area, set the scrollBarsEnabled property to true.

See also QMdiSubWindow.

## Member Type Documentation

### enum QMdiArea::AreaOption
flags QMdiArea::AreaOptions

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

Constant | Value | Description
--- | --- | ---
`QMdiArea::DontMaximizeSubWindowOnActivation` | `0x1` | When 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.

The AreaOptions type is a typedef for QFlags<AreaOption>. It stores an OR combination of AreaOption values.

### enum QMdiArea::WindowOrder

Specifies the order in which child windows are returned from subWindowList(). The cascadeSubWindows() and tileSubWindows() functions follow this order when arranging the windows.

Constant | Value | Description
--- | --- | ---
`QMdiArea::CreationOrder` | `0` | The windows are returned in the order of their creation
`QMdiArea::StackingOrder` | `1` | The windows are returned in the order in which they are stacked; the top-most window is last in the list.

## Property Documentation

### 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 )

### scrollBarsEnabled : bool

This property holds whether the workspace provides scroll bars.

If this property is true, the MDI area will provide scroll bars if any of the subwindows extend beyond the edges of the MDI area. The scroll bar policy is Qt::ScrollBarAsNeeded.

When subwindows are resized the MDI area will increase in size to contain the subwindows. If this property is false (the default), resizing child windows out of the visible area of the workspace is not permitted, although it is still possible to position them partially outside the visible area. Unless the AllowOutsideArea subwindow option is enabled, it is not possible to place the windows so that they can not be handled by the mouse.

Access functions:

- bool scrollBarsEnabled () const
- void setScrollBarsEnabled ( bool enable )

See also QAbstractScrollArea::horizontalScrollBar(), QAbstractScrollArea::verticalScrollBar(), and QMdiSubWindow::SubWindowOption.

## Member Function Documentation

### QMdiArea::QMdiArea ( QWidget * parent = 0 )

Constructs an empty mdi area. parent is passed to QWidget's constructor.

### QMdiArea::~QMdiArea ()

Destroys the MDI area.

### void QMdiArea::activateNextSubWindow () `[slot]`

Gives the keyboard focus to the next window in the list of child windows. The windows are activated in the order in which they are stacked (StackingOrder).

See also activatePreviousSubWindow().

### void QMdiArea::activatePreviousSubWindow () `[slot]`

Gives the keyboard focus to the previous window in the list of child windows. The windows are activated in the order in which they are stacked (StackingOrder).

See also activateNextSubWindow().

### QMdiSubWindow * QMdiArea::activeSubWindow () const

Returns a pointer to the current active subwindow. If no window is currently active, 0 is returned.

Subwindows are treated as top-level windows with respect to window state, i.e., if a widget outside the MDI area is the active window, no subwindow will be active. Note that if a widget in the window in which the MDI area lives gains focus, the window will be activated. (may skip last sentence)

See also setActiveSubWindow() and Qt::WindowState.

### QMdiSubWindow * QMdiArea::addSubWindow ( QWidget * widget, Qt::WindowFlags windowFlags = 0 )

Adds widget as a new subwindow to the MDI area. If windowFlags are non-zero, they will override the flags set on the widget.

The widget can be either a QMdiSubWindow or another QWidget (in which case the MDI area will create a subwindow and set the widget as the internal widget).

         QMdiArea mdiArea;
         QMdiSubWindow *subWindow1 = new QMdiSubWindow;
         subWindow1->setWidget(internalWidget1);
         subWindow1->setAttribute(Qt::WA_DeleteOnClose);
         mdiArea.addSubWindow(subWindow1);

         QMdiSubWindow *subWindow2 =
             mdiArea.addSubWindow(internalWidget2);

When you create your own subwindow, you must set the Qt::WA_DeleteOnClose widget attribute for the window to be deleted when closed in the MDI area. If not, the window will be hidden and the MDI area will not activate the next subwindow.

Returns the QMdiSubWindow that is added to the MDI area.

See also removeSubWindow().

### void QMdiArea::cascadeSubWindows () `[slot]`

Arranges all the child windows in a cascade pattern.

See also tileSubWindows().

### void QMdiArea::closeActiveSubWindow () `[slot]`

Closes the active subwindow.

See also closeAllSubWindows().

### void QMdiArea::closeAllSubWindows () `[slot]`

Closes all subwindows by sending a QCloseEvent to each window. You may recieve subWindowActivated() signals from subwindows before they are closed (if the MDI area activates the subwindow when another is closing).

Subwindows that ignore the close event will remain open.

See also closeActiveSubWindow().

### void QMdiArea::removeSubWindow ( QWidget * widget )

Removes widget from the MDI area. The widget must be either a QMdiSubWindow or a widget that is the internal widget of a subwindow. Note that the subwindow is not deleted by QMdiArea and that its parent is set to 0.

See also addSubWindow().

### void QMdiArea::setActiveSubWindow ( QMdiSubWindow * window ) `[slot]`

Activates the subwindow window. If window is 0, any current active window is deactivated.

See also activeSubWindow().

### void QMdiArea::setOption ( AreaOption option, bool on = true )

If on is true, option is enabled on the MDI area; otherwise it is disabled. See AreaOption for the effect of each option.

See also AreaOption and testOption().

### void QMdiArea::setupViewport ( QWidget * viewport ) `[protected slot]`

This slot is called by QAbstractScrollArea after setViewport() has been called. Reimplement this function in a subclass of QMdiArea to initialize the new viewport before it is used.

See also setViewport().

### void QMdiArea::subWindowActivated ( QMdiSubWindow * window ) `[signal]`

QMdiArea emits this signal after window has been activated. When window is 0, QMdiArea has just deactivated its last active window, and there are no active windows on the workspace.

See also QMdiArea::activeSubWindow().

### QList<QMdiSubWindow *> QMdiArea::subWindowList ( WindowOrder order = CreationOrder ) const

Returns a list of all subwindows in the MDI area. If order is CreationOrder (the default), the windows are sorted in the order in which they were inserted into the workspace. If order is StackingOrder, the windows are listed in their stacking order, with the topmost window as the last item in the list.

See also WindowOrder.

### bool QMdiArea::testOption ( AreaOption option ) const

Returns true if option is enabled; otherwise returns false.

See also AreaOption and setOption().

### void QMdiArea::tileSubWindows () `[slot]`

Arranges all child windows in a tile pattern.

See also cascadeSubWindows().