QMdiArea Class
QMdiArea 提供一个显示MDI窗口的区域. 更多...
头文件: | #include <QMdiArea> |
qmake: | QT += widgets |
开始支持版本: | Qt 4.3 |
基类: | QAbstractScrollArea |
公有类型
enum | AreaOption { DontMaximizeSubWindowOnActivation } |
flags | AreaOptions |
enum | ViewMode { SubWindowView, TabbedView } |
enum | WindowOrder { CreationOrder, StackingOrder, ActivationHistoryOrder } |
属性
|
|
- 3 个属性继承自 QAbstractScrollArea
- 6 个属性继承自 QFrame
- 59 个属性继承自 QWidget
- 1 个属性继承自 QObject
公有函数
QMdiArea(QWidget *parent = Q_NULLPTR) | |
~QMdiArea() | |
WindowOrder | activationOrder() const |
QMdiSubWindow * | activeSubWindow() const |
QMdiSubWindow * | addSubWindow(QWidget *widget, Qt::WindowFlags windowFlags = Qt::WindowFlags()) |
QBrush | background() const |
QMdiSubWindow * | currentSubWindow() const |
bool | documentMode() const |
void | removeSubWindow(QWidget *widget) |
void | setActivationOrder(WindowOrder order) |
void | setBackground(const QBrush &background) |
void | setDocumentMode(bool enabled) |
void | setOption(AreaOption option, bool on = true) |
void | setTabPosition(QTabWidget::TabPosition position) |
void | setTabShape(QTabWidget::TabShape shape) |
void | setTabsClosable(bool closable) |
void | setTabsMovable(bool movable) |
void | setViewMode(ViewMode mode) |
QList<QMdiSubWindow *> | subWindowList(WindowOrder order = CreationOrder) const |
QTabWidget::TabPosition | tabPosition() const |
QTabWidget::TabShape | tabShape() const |
bool | tabsClosable() const |
bool | tabsMovable() const |
bool | testOption(AreaOption option) const |
ViewMode | viewMode() const |
重新实现的公有函数
virtual QSize | minimumSizeHint() const |
virtual QSize | sizeHint() const |
- 20 个公有函数继承自 QAbstractScrollArea
- 14 个公有函数继承自 QFrame
- 214 个公有函数继承自 QWidget
- 32 个公有函数继承自 QObject
- 14 个公有函数继承自 QPaintDevice
公有槽函数
void | activateNextSubWindow() |
void | activatePreviousSubWindow() |
void | cascadeSubWindows() |
void | closeActiveSubWindow() |
void | closeAllSubWindows() |
void | setActiveSubWindow(QMdiSubWindow *window) |
void | tileSubWindows() |
信号
void | subWindowActivated(QMdiSubWindow *window) |
重新实现的受保护函数
virtual void | childEvent(QChildEvent *childEvent) |
virtual bool | event(QEvent *event) |
virtual bool | eventFilter(QObject *object, QEvent *event) |
virtual void | paintEvent(QPaintEvent *paintEvent) |
virtual void | resizeEvent(QResizeEvent *resizeEvent) |
virtual void | scrollContentsBy(int dx, int dy) |
virtual void | showEvent(QShowEvent *showEvent) |
virtual void | timerEvent(QTimerEvent *timerEvent) |
virtual bool | viewportEvent(QEvent *event) |
- 20 个受保护的函数继承自 QAbstractScrollArea
- 4 个受保护的函数继承自 QFrame
- 35 个受保护的函数继承自 QWidget
- 9 个受保护的函数继承自 QObject
- 1 个受保护的函数继承自 QPaintDevice
Protected Slots
virtual void | setupViewport(QWidget *viewport) |
- 1 个受保护的槽函数继承自 QWidget
其他继承的成员
- 1 个公有变量继承自 QObject
- 5 个静态公有成员继承自 QWidget
- 10 个静态公有成员继承自 QObject
- 20 个受保护的函数继承自 QAbstractScrollArea
- 4 个受保护的函数继承自 QFrame
- 35 个受保护的函数继承自 QWidget
- 9 个受保护的函数继承自 QObject
- 1 个受保护的函数继承自 QPaintDevice
- 2 个受保护的变量继承自 QObject
- 1 protected type inherited from QPaintDevice
详细描述
QMdiArea 提供一个显示MDI窗口的区域.
QMdiArea 本质上相当于MDI窗口的窗口管理器. 例如, 它绘制它管理的窗口, 并以层叠或平铺方式排列它们. 在MDI应用程序中, QMdiArea 通常作为 QMainWindow 的中心窗口widget, 但是也可以放在布局中. 下列代码将QMdiArea加入主窗口:
QMainWindow *mainWindow = new QMainWindow; mainWindow->setCentralWidget(mdiArea);
不同于顶级窗口的管理器, QMdiArea 支持所有窗口标志 (Qt::WindowFlags) . 如果某个样式 (如., WindowShadeButtonHint) 不被支持, 你仍然可以使用 showShaded()绘制窗口阴影.
QMdiSubWindow是 QMdiArea 的子窗口. 你可以调用 addSubWindow()在QMdiArea中加入QMdiSubWindow. addSubWindow函数的参数通常是 QWidget,但也可以直接传递 QMdiSubWindow. QMdiSubWindow是 QWidget 的派生类, 你可以使用与普通顶级窗口相同的API. QMdiSubWindow 具有MDI窗口的特定行为. 详见 QMdiSubWindow.
子窗口通过键盘焦点或调用 setFocus() 激活. 用户可以用通常的方式移动焦点以激活窗口. 当窗口焦点改变时, QMdiArea会发出subWindowActivated() 信号, 调用 activeSubWindow() 获取活动窗口.
便捷函数 subWindowList() 返回所有子窗口列表. 这个信息可以在窗口列表的弹出菜单使用.
子窗口依照当前的 WindowOrder 排序. 这个窗口列表用于 subWindowList(), activateNextSubWindow(), activatePreviousSubWindow(). 此外, 窗口列表也可在 cascadeSubWindows() 和 tileSubWindows()函数使用, 前者层叠窗口, 后者平铺窗口.
QMdiArea 提供两种布局函数: cascadeSubWindows() 和 tileSubWindows(). 这两个函数公有槽函数, 很容易使用菜单连接.
![]() | ![]() |
注意: QMdiArea 的默认滚动条属性是 Qt::ScrollBarAlwaysOff.
参见 QMdiSubWindow.
成员类型
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::ViewMode
This enum describes the view mode of the area; i.e. how sub-windows will be displayed.
Constant | Value | Description |
---|---|---|
QMdiArea::SubWindowView | 0 | Display sub-windows with window frames (default). |
QMdiArea::TabbedView | 1 | Display sub-windows with tabs in a tab bar. |
This enum was introduced or modified in Qt 4.4.
参见 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.
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, with the top-most window being last in the list. |
QMdiArea::ActivationHistoryOrder | 2 | The windows are returned in the order in which they were activated. |
参见 subWindowList().
属性
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.
访问函数:
WindowOrder | activationOrder() const |
void | setActivationOrder(WindowOrder order) |
参见 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).
访问函数:
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.
访问函数:
bool | documentMode() const |
void | setDocumentMode(bool enabled) |
参见 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.
访问函数:
QTabWidget::TabPosition | tabPosition() const |
void | setTabPosition(QTabWidget::TabPosition position) |
参见 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.
访问函数:
QTabWidget::TabShape | tabShape() const |
void | setTabShape(QTabWidget::TabShape shape) |
参见 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.
访问函数:
bool | tabsClosable() const |
void | setTabsClosable(bool closable) |
参见 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.
访问函数:
bool | tabsMovable() const |
void | setTabsMovable(bool movable) |
参见 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.
访问函数:
ViewMode | viewMode() const |
void | setViewMode(ViewMode mode) |
参见 ViewMode, setTabShape(), and setTabPosition().
成员函数
QMdiArea::QMdiArea(QWidget *parent = Q_NULLPTR)
Constructs an empty mdi area. parent is passed to QWidget's constructor.
QMdiArea::~QMdiArea()
Destroys the MDI area.
[slot]
void QMdiArea::activateNextSubWindow()
Gives the keyboard focus to another window in the list of child windows. The window activated will be the next one determined by the current activation order.
参见 activatePreviousSubWindow() and QMdiArea::WindowOrder.
[slot]
void QMdiArea::activatePreviousSubWindow()
Gives the keyboard focus to another window in the list of child windows. The window activated will be the previous one determined by the current activation order.
参见 activateNextSubWindow() and QMdiArea::WindowOrder.
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.
参见 setActiveSubWindow() and Qt::WindowState.
QMdiSubWindow *QMdiArea::addSubWindow(QWidget *widget, Qt::WindowFlags windowFlags = Qt::WindowFlags())
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).
Note: Once the subwindow has been added, its parent will be the viewport widget of the QMdiArea.
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 if you want 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.
参见 removeSubWindow().
[slot]
void QMdiArea::cascadeSubWindows()
Arranges all the child windows in a cascade pattern.
参见 tileSubWindows().
[virtual protected]
void QMdiArea::childEvent(QChildEvent *childEvent)
重新实现 QObject::childEvent().
[slot]
void QMdiArea::closeActiveSubWindow()
Closes the active subwindow.
参见 closeAllSubWindows().
[slot]
void QMdiArea::closeAllSubWindows()
Closes all subwindows by sending a QCloseEvent to each window. You may receive 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.
参见 closeActiveSubWindow().
QMdiSubWindow *QMdiArea::currentSubWindow() const
Returns a pointer to the current subwindow, or 0 if there is no current subwindow.
This function will return the same as activeSubWindow() if the QApplication containing QMdiArea is active.
参见 activeSubWindow() and QApplication::activeWindow().
[virtual protected]
bool QMdiArea::event(QEvent *event)
重新实现 QObject::event().
[virtual protected]
bool QMdiArea::eventFilter(QObject *object, QEvent *event)
重新实现 QObject::eventFilter().
[virtual]
QSize QMdiArea::minimumSizeHint() const
重新实现 QWidget::minimumSizeHint().
[virtual protected]
void QMdiArea::paintEvent(QPaintEvent *paintEvent)
重新实现 QWidget::paintEvent().
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 widget is never actually deleted by QMdiArea. If a QMdiSubWindow is passed in its parent is set to 0 and it is removed, but if an internal widget is passed in the child widget is set to 0 but the QMdiSubWindow is not removed.
参见 addSubWindow().
[virtual protected]
void QMdiArea::resizeEvent(QResizeEvent *resizeEvent)
重新实现 QWidget::resizeEvent().
[virtual protected]
void QMdiArea::scrollContentsBy(int dx, int dy)
重新实现 QAbstractScrollArea::scrollContentsBy().
[slot]
void QMdiArea::setActiveSubWindow(QMdiSubWindow *window)
Activates the subwindow window. If window is 0, any current active window is deactivated.
参见 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.
参见 AreaOption and testOption().
[virtual protected slot]
void QMdiArea::setupViewport(QWidget *viewport)
重新实现 QAbstractScrollArea::setupViewport().
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.
参见 setViewport().
[virtual protected]
void QMdiArea::showEvent(QShowEvent *showEvent)
重新实现 QWidget::showEvent().
[virtual]
QSize QMdiArea::sizeHint() const
重新实现 QWidget::sizeHint().
[signal]
void QMdiArea::subWindowActivated(QMdiSubWindow *window)
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.
参见 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. If order is ActivationHistoryOrder, the windows are listed according to their recent activation history.
参见 WindowOrder.
bool QMdiArea::testOption(AreaOption option) const
Returns true
if option is enabled; otherwise returns false
.
参见 AreaOption and setOption().
[slot]
void QMdiArea::tileSubWindows()
Arranges all child windows in a tile pattern.
参见 cascadeSubWindows().
[virtual protected]
void QMdiArea::timerEvent(QTimerEvent *timerEvent)
重新实现 QObject::timerEvent().