6.0.0-rc4Source

QMdiArea Class

The QMdiArea class provides an area in which sub-windows are shown, for an application with many documents. More…

Header#include <QMdiArea>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQAbstractScrollArea

List of all members, including inherited members

Public Types

Public Functions

QMdiArea(QWidget *parent = nullptr)
~QMdiArea()
QMdiSubWindow *addSubWindow(QWidget *widget, Qt::WindowFlags flags = Qt::WindowFlags())
voidremoveSubWindow(QWidget *widget)
QList<QMdiSubWindow *>subWindowList(WindowOrder order = CreationOrder) const
QMdiSubWindow *currentSubWindow() const
QMdiSubWindow *activeSubWindow() const
QBrushbackground() const
voidsetBackground(const QBrush &background)
WindowOrderactivationOrder() const
voidsetActivationOrder(WindowOrder order)
voidsetOption(AreaOption option, bool on = true)
booltestOption(AreaOption option) const
ViewModeviewMode() const
voidsetViewMode(ViewMode mode)
booltabsClosable() const
voidsetTabsClosable(bool closable)
booltabsMovable() const
voidsetTabsMovable(bool movable)

Reimplemented Public Functions

Public Slots

Signals

Reimplemented Protected Functions

boolviewportEvent(QEvent *event)
voidresizeEvent(QResizeEvent *event)

Detailed Description

An MDI area holds QMdiSubWindow windows: it lays them out, keeps one of them active, and can tile or cascade them. It is usually the central widget of a QMainWindow:

auto *area = new QMdiArea;
window.setCentralWidget(area);
QMdiSubWindow *notes = area->addSubWindow(new QPlainTextEdit);
notes->setWindowTitle("Notes");
notes->show();
connect(area, &QMdiArea::subWindowActivated, [](QMdiSubWindow *w) { updateMenus(w); });

In TabbedView mode the area shows a tab bar with a tab for each sub-window, and the active sub-window fills the area without its frame.

See also QMdiSubWindow.

Differences from Qt

The scroll bars are always off: sub-windows that are moved out of the area are cut off. There is no setDocumentMode(), setTabShape() or setTabPosition() (the tabs are at the top), and the background is filled with a color, not tiled with an image.

Member Type Documentation

enum QMdiArea::AreaOption

Options of the area. AreaOptions is a typedef for QFlags<AreaOption>.

ConstantDescription
QMdiArea::DontMaximizeSubWindowOnActivationActivating a sub-window does not maximize it when the active one was maximized.

typedef QMdiArea::AreaOptions

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

enum QMdiArea::ViewMode

How the sub-windows are shown.

ConstantDescription
QMdiArea::SubWindowViewAs windows with frames, the default.
QMdiArea::TabbedViewAs tabs: the active one fills the area.

enum QMdiArea::WindowOrder

The orders of subWindowList(), and of activateNextSubWindow().

ConstantDescription
QMdiArea::CreationOrderThe order the sub-windows were added in.
QMdiArea::StackingOrderFrom the bottom to the top.
QMdiArea::ActivationHistoryOrderFrom the least recently to the most recently active.

Member Function Documentation

[explicit] QMdiArea::QMdiArea(QWidget *parent = nullptr)

Constructs an empty MDI area with the given parent.

[override] QMdiArea::~QMdiArea()

Destroys the area and its sub-windows.

[slot] void QMdiArea::activateNextSubWindow()

Activates the visible sub-window after the active one in the activation order, going round at the end.

[slot] void QMdiArea::activatePreviousSubWindow()

Activates the visible sub-window before the active one in the activation order, going round at the start.

WindowOrder QMdiArea::activationOrder() const

Returns the order of activateNextSubWindow(), CreationOrder by default.

QMdiSubWindow * QMdiArea::activeSubWindow() const

Returns the active sub-window, or nullptr.

QMdiSubWindow * QMdiArea::addSubWindow(QWidget *widget, Qt::WindowFlags flags = Qt::WindowFlags())

Adds widget to the area in a new sub-window with the window flags, and returns the sub-window. A QMdiSubWindow is added as it is. The sub-window is shown with the area; if the area is visible already, call show() on it. The first sub-window becomes active.

See also removeSubWindow().

QBrush QMdiArea::background() const

Returns the brush that fills the area behind the sub-windows; by default the dark color of the palette.

[slot] void QMdiArea::cascadeSubWindows()

Lays the visible sub-windows out one behind the other, each a step further down and to the right.

See also tileSubWindows().

[slot] void QMdiArea::closeActiveSubWindow()

Closes the active sub-window.

[slot] void QMdiArea::closeAllSubWindows()

Closes all the sub-windows. A sub-window whose widget ignores the close event stays.

QMdiSubWindow * QMdiArea::currentSubWindow() const

Returns the sub-window that is current: the active one, or the one that was active last while the window of the area was not active.

[override] QSize QMdiArea::minimumSizeHint() const

Reimplements QAbstractScrollArea::minimumSizeHint().

void QMdiArea::removeSubWindow(QWidget *widget)

Removes widget from the area without deleting it. For a QMdiSubWindow, the sub-window leaves the area and no longer has a parent; for the widget of a sub-window, the widget leaves its sub-window, which stays.

See also addSubWindow().

[override, protected] void QMdiArea::resizeEvent(QResizeEvent *event)

Reimplements QAbstractScrollArea::resizeEvent().

void QMdiArea::setActivationOrder(WindowOrder order)

Sets the order of activateNextSubWindow() to order.

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

Makes window the active sub-window: it is raised, gets the focus, and the one that was active stops being so. Emits subWindowActivated() if it changes. With nullptr no sub-window is active.

See also activeSubWindow().

void QMdiArea::setBackground(const QBrush &background)

Sets the brush that fills the area behind the sub-windows to background.

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

Sets option if on is true, and clears it otherwise.

void QMdiArea::setTabsClosable(bool closable)

Sets whether the tabs of the tabbed view have close buttons to closable.

void QMdiArea::setTabsMovable(bool movable)

Sets whether the tabs of the tabbed view can be dragged into another order to movable.

void QMdiArea::setViewMode(ViewMode mode)

Sets how the sub-windows are shown to mode.

[override] QSize QMdiArea::sizeHint() const

Reimplements QAbstractScrollArea::sizeHint().

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

This signal is emitted when the active sub-window changes to window, which is nullptr if there is none.

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

Returns the sub-windows in the given order.

bool QMdiArea::tabsClosable() const

Returns whether the tabs of the tabbed view have close buttons. The default is false.

bool QMdiArea::tabsMovable() const

Returns whether the tabs of the tabbed view can be dragged into another order. The default is false.

bool QMdiArea::testOption(AreaOption option) const

Returns whether option is set.

[slot] void QMdiArea::tileSubWindows()

Lays the visible sub-windows out in a grid that fills the area.

See also cascadeSubWindows().

ViewMode QMdiArea::viewMode() const

Returns how the sub-windows are shown, SubWindowView by default.

[override, protected] bool QMdiArea::viewportEvent(QEvent *event)

Reimplements QAbstractScrollArea::viewportEvent().

The viewport is filled with the background, and maximized sub-windows follow its size.