ApplicationWindow QML Type
支持页眉和页脚的样式化顶层窗口。更多
Import Statement: | import QtQuick.Controls |
Inherits: |
属性
- activeFocusControl : Control
- background : Item
- bottomPadding : real
(since 6.9)
- contentData : list<QtObject>
- contentItem : Item
- font : font
- footer : Item
- header : Item
- leftPadding : real
(since 6.9)
- locale : Locale
- menuBar : Item
(since QtQuick.Controls 2.3 (Qt 5.10))
- rightPadding : real
(since 6.9)
- topPadding : real
(since 6.9)
附属物业
- activeFocusControl : Control
- contentItem : Item
- footer : Item
- header : Item
- menuBar : Item
(since QtQuick.Controls 2.3 (Qt 5.10))
- window : ApplicationWindow
详细说明
ApplicationWindow 是一个Window ,可方便地为窗口添加menu bar 、header 和footer 项。
您可以将 ApplicationWindow 声明为应用程序的根项,并使用QQmlApplicationEngine 运行它。这样,您就可以通过 QML 控制窗口的属性、外观和布局。
import QtQuick.Controls 2.12 ApplicationWindow { visible: true menuBar: MenuBar { // ... } header: ToolBar { // ... } footer: TabBar { // ... } StackView { anchors.fill: parent } }
注: 默认情况下,ApplicationWindow 是不可见的。
附加应用程序窗口属性
由于 QML 的范围和命名解析(Scope and Naming Resolution)工作原理,可以在其子 QML 对象的任何地方引用应用程序根元素的id
。尽管这种方法对许多应用程序和用例都很好,但对通用 QML 组件来说,这种方法可能是不可接受的,因为它会产生对周围环境的依赖。
ApplicationWindow 提供了一组附加属性,可用于从无法直接访问窗口的地方访问窗口及其构建模块,而不会对特定窗口产生依赖id
。使用 ApplicationWindow 附加属性的 QML 组件可在任何窗口中工作,而不管它是id
。
安全区域
自 Qt 6.9 以来,ApplicationWindow 会自动为任何窗口报告的safe area margins 添加填充到contentItem 。这将确保contentItem 保持在窗口的安全区域内,而背景项则覆盖整个窗口。
如果在窗口的contentItem 中手动设置安全区域边距,则可通过topPadding 、leftPadding 、rightPadding 和bottomPadding 属性覆盖默认值:
ApplicationWindow { // Remove automatic safe area padding topPadding: 0 Flickable { // Inset content by safe area margin topMargin: SafeArea.margins.top } }
header 、footer 和menuBar 属性不会自动为安全区域边距添加任何填充。但是,根据使用的样式,样式在实现ToolBar 、TabBar 和MenuBar 时可能会考虑安全区域。
另请参阅 Qt Quick Controls 中的Customizing ApplicationWindow(自定义应用程序窗口)、Overlay 、Page 、Container Controls(容器控件)和Focus Management(焦点管理)。
属性文档
activeFocusControl : Control |
该属性保存当前具有活动焦点的控件,如果没有具有活动焦点的控件,则保存null
。
Window::activeFocusItem 和ApplicationWindow::activeFocusControl 的区别在于,前者可以指向控件的构件,而后者则指向外层控件。例如,当SpinBox 有焦点时,activeFocusItem 指向编辑器,而 activeFocusControl 指向SpinBox 本身。
另请参阅 Window::activeFocusItem 。
background : Item |
该属性包含背景项。
背景项堆叠在content item 下方,但高于窗口的background color 。
例如,背景项对于图像和渐变非常有用,但对于纯色来说,color 属性更可取,因为它不需要创建项。
注意: 如果背景项没有指定明确的大小,它会自动跟随控件的大小。在大多数情况下,无需为背景项指定宽度或高度。
另请参阅 自定义 ApplicationWindow、contentItem 、header 和footer 。
bottomPadding : real |
该属性用于保存窗口内容项的底部填充。除非明确设置,否则该值将反映窗口的safe area margins 。
此属性在 Qt 6.9 中引入。
另请参阅 topPadding,leftPadding, 和rightPadding 。
该默认属性包含声明为窗口子对象的所有对象的列表。
数据属性允许您在ApplicationWindow 中自由混合可视化子窗口、资源和其他窗口。
如果将一个项目指定给 contentData 列表,它就会成为窗口contentItem 的子项,从而显示在窗口内部。项的父窗口将是窗口的contentItem 。
一般情况下无需引用 contentData 属性,因为它是ApplicationWindow 的默认属性,因此所有子项都会自动分配给该属性。
另请参阅 contentItem 。
contentItem : Item |
该属性包含窗口内容项。
该内容项堆叠在background 项之上,以及menuBar 、header 和footer 项之下。
自 Qt 6.9 起,ApplicationWindow 将自动为窗口报告的任何safe area margins 的 contentItem 添加 padding。要覆盖填充,请使用各个填充属性。
另请参阅 background,menuBar,header,footer,topPadding,bottomPadding,leftPadding 和rightPadding 。
font : font |
该属性包含当前为窗口设置的字体。
默认字体取决于系统环境。QGuiApplication 维护一个系统/主题字体,作为所有应用程序窗口的默认字体。您也可以在加载任何 QML 之前,通过向QGuiApplication::setFont() 传递自定义字体来设置窗口的默认字体。最后,字体会与 Qt 的字体数据库进行匹配,以找到最佳匹配。
ApplicationWindow 将显式字体属性传播给子控件。如果更改了窗口字体的特定属性,该属性会传播到窗口中的所有子控件,并覆盖该属性的任何系统默认值。
另请参阅 Control::font 。
footer : Item |
该属性用于保存窗口页脚项。页脚项位于底部,并根据窗口宽度调整大小。默认值为null
。
ApplicationWindow { footer: ToolBar { // ... } }
注: 将ToolBar 、TabBar 或DialogButtonBox 指定为窗口页脚会自动将相应的ToolBar::position 、TabBar::position 或DialogButtonBox::position 属性设置为Footer
。
另请参阅 menuBar,header, 和Page::footer 。
header : Item |
该属性包含窗口页眉项。页眉项位于窗口顶部、菜单栏下方,并根据窗口宽度调整大小。默认值为null
。
ApplicationWindow { header: TabBar { // ... } }
注: 将ToolBar 、TabBar 或DialogButtonBox 指定为窗口页眉会自动将相应的ToolBar::position 、TabBar::position 或DialogButtonBox::position 属性设置为Header
。
另请参阅 menuBar,footer, 和Page::header 。
leftPadding : real |
该属性用于保存窗口内容项的左填充。除非明确设置,否则该值将反映窗口的safe area margins 。
此属性在 Qt 6.9 中引入。
另请参阅 bottomPadding,topPadding, 和rightPadding 。
locale : Locale |
该属性用于保存窗口的 locale。
默认语言取决于系统环境。您可以在加载任何 QML 之前调用QLocale::setDefault() 来设置默认 locale。
ApplicationWindow 该属性会将本地化传播给子控件。如果更改窗口的 locale,该 locale 会传播到窗口中的所有子控件,覆盖系统默认 locale。
另请参阅 Control::locale 。
menuBar : Item |
该属性用于保存窗口菜单栏。菜单栏位于窗口顶部、标题上方,并根据窗口宽度调整大小。默认值为null
。
ApplicationWindow { menuBar: MenuBar { // ... } }
该属性在 QtQuick.Controls 2.3 (Qt 5.10) 中引入。
rightPadding : real |
该属性用于保存窗口内容项的右填充。除非明确设置,否则该值将反映窗口的safe area margins 。
该属性在 Qt 6.9 中引入。
另请参阅 bottomPadding,leftPadding, 和topPadding 。
topPadding : real |
该属性用于保存窗口内容项的顶部填充。除非明确设置,否则该值将反映窗口的safe area margins 。
此属性在 Qt 6.9 中引入。
另请参阅 bottomPadding,leftPadding, 和rightPadding 。
附加属性文档
ApplicationWindow.activeFocusControl : Control |
该附加属性保存当前拥有活动焦点的控件,如果没有拥有活动焦点的控件,则保存null
。该属性可附加到任何项目。如果项目不在窗口中,或窗口没有活动焦点,则值为null
。
另请参阅 Window::activeFocusItem 和Attached ApplicationWindow Properties 。
ApplicationWindow.contentItem : Item |
该附加属性用于保存窗口内容项目。该属性可附加到任何项目。如果项目不在ApplicationWindow 中,则值为null
。
ApplicationWindow.footer : Item |
该附加属性用于保存窗口页脚项目。该属性可附加到任何项目。如果项目不在ApplicationWindow 中,或窗口没有页脚项目,则值为null
。
ApplicationWindow.header : Item |
该附加属性用于保存窗口页眉项目。该属性可附加到任何项目。如果项目不在ApplicationWindow 中,或窗口没有页眉项目,则值为null
。
ApplicationWindow.menuBar : Item |
该附加属性用于保存窗口菜单栏。该属性可附加到任何项目。如果项目不在ApplicationWindow 中,或窗口没有菜单栏,则值为null
。
该属性在 QtQuick.Controls 2.3 (Qt 5.10) 中引入。
ApplicationWindow.window : ApplicationWindow |
该附加属性用于保存应用程序窗口。该属性可附加到任何项目。如果项目不在ApplicationWindow 中,其值为null
。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.