QMdiArea Class
The QMdiArea class provides an area in which sub-windows are shown, for an application with many documents. More…
| Header | #include <QMdiArea> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QAbstractScrollArea |
List of all members, including inherited members
Public Types
| enum | AreaOption |
| typedef | AreaOptions |
| enum | WindowOrder |
| enum | ViewMode |
Public Functions
| QMdiArea(QWidget *parent = nullptr) | |
| ~QMdiArea() | |
| QMdiSubWindow * | addSubWindow(QWidget *widget, Qt::WindowFlags flags = Qt::WindowFlags()) |
| void | removeSubWindow(QWidget *widget) |
| QList<QMdiSubWindow *> | subWindowList(WindowOrder order = CreationOrder) const |
| QMdiSubWindow * | currentSubWindow() const |
| QMdiSubWindow * | activeSubWindow() const |
| QBrush | background() const |
| void | setBackground(const QBrush &background) |
| WindowOrder | activationOrder() const |
| void | setActivationOrder(WindowOrder order) |
| void | setOption(AreaOption option, bool on = true) |
| bool | testOption(AreaOption option) const |
| ViewMode | viewMode() const |
| void | setViewMode(ViewMode mode) |
| bool | tabsClosable() const |
| void | setTabsClosable(bool closable) |
| bool | tabsMovable() const |
| void | setTabsMovable(bool movable) |
Reimplemented Public Functions
| QSize | sizeHint() const |
| QSize | minimumSizeHint() const |
Public Slots
| void | setActiveSubWindow(QMdiSubWindow *window) |
| void | tileSubWindows() |
| void | cascadeSubWindows() |
| void | closeActiveSubWindow() |
| void | closeAllSubWindows() |
| void | activateNextSubWindow() |
| void | activatePreviousSubWindow() |
Signals
| void | subWindowActivated(QMdiSubWindow *window) |
Reimplemented Protected Functions
| bool | viewportEvent(QEvent *event) |
| void | resizeEvent(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>.
| Constant | Description |
|---|---|
QMdiArea::DontMaximizeSubWindowOnActivation | Activating 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.
| Constant | Description |
|---|---|
QMdiArea::SubWindowView | As windows with frames, the default. |
QMdiArea::TabbedView | As tabs: the active one fills the area. |
enum QMdiArea::WindowOrder
The orders of subWindowList(), and of activateNextSubWindow().
| Constant | Description |
|---|---|
QMdiArea::CreationOrder | The order the sub-windows were added in. |
QMdiArea::StackingOrder | From the bottom to the top. |
QMdiArea::ActivationHistoryOrder | From the least recently to the most recently active. |
Member Function Documentation
QMdiArea::QMdiArea(QWidget *parent = nullptr)
Constructs an empty MDI area with the given parent.
QMdiArea::~QMdiArea()
Destroys the area and its sub-windows.
void QMdiArea::activateNextSubWindow()
Activates the visible sub-window after the active one in the activation order, going round at the end.
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.
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().
void QMdiArea::closeActiveSubWindow()
Closes the active sub-window.
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.
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().
void QMdiArea::resizeEvent(QResizeEvent *event)
Reimplements QAbstractScrollArea::resizeEvent().
void QMdiArea::setActivationOrder(WindowOrder order)
Sets the order of activateNextSubWindow() to order.
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.
QSize QMdiArea::sizeHint() const
Reimplements QAbstractScrollArea::sizeHint().
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.
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.
bool QMdiArea::viewportEvent(QEvent *event)
Reimplements QAbstractScrollArea::viewportEvent().
The viewport is filled with the background, and maximized sub-windows follow its size.