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
ApplicationWindow {
visible: true
menuBar: MenuBar {
// ...
}
header: ToolBar {
// ...
}
footer: TabBar {
// ...
}
StackView {
anchors.fill: parent
}
}注意:默认情况下 ,ApplicationWindow 不可见。
关联的 ApplicationWindow 属性
由于 QML 中作用域和命名解析的运作方式,可以在应用程序根元素的子 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 时可能会考虑安全区域。
另请参阅 《自定义 ApplicationWindow》、《Overlay 》、《Page 》、《容器控件》以及 Qt Quick Controls 中的“焦点管理”。
属性文档
activeFocusControl : Control [read-only]
该属性保存当前具有活动焦点的控件;如果没有具有活动焦点的控件,则保存null 。
Window::activeFocusItem 与 ApplicationWindow::activeFocusControl 之间的区别在于:前者可能指向控件的组成部件,而后者则指向包含该控件的父控件。例如,当SpinBox 处于焦点状态时,activeFocusItem 指向编辑器,而 activeFocusControl 则指向SpinBox 本身。
另请参阅 Window::activeFocusItem 。
background : Item
此属性用于存储背景项。
背景项的堆叠顺序位于窗口的“content item ”下方,但位于“background color ”上方。
背景项对于图像和渐变等非常有用,但对于纯色,建议使用color 属性,因为它无需创建项目。
注意:如果 未显式指定背景项的大小,它将自动遵循控件的大小。在大多数情况下,无需为背景项指定宽度或高度。
另请参阅 “自定义 ApplicationWindow”、“contentItem ”、“header ”和“footer ”。
bottomPadding : real [since 6.9]
该属性存储窗口内容项的底部内边距。除非显式设置,否则其值即为窗口的safe area margins 。
该属性在 Qt 6.9 中引入。
另请参阅 topPadding 、leftPadding 和rightPadding 。
contentData : list<QtObject> [default]
此默认属性包含所有被声明为该窗口子元素的对象列表。
data 属性允许您在“ApplicationWindow ”中自由组合视觉子元素、资源和其他窗口。
如果您将一个 Item 分配给 contentData 列表,它就会成为窗口的contentItem 的子元素,从而显示在窗口内部。该项的父项将是窗口的contentItem 。
通常无需显式引用 contentData 属性,因为它是 `ApplicationWindow ` 的默认属性,因此所有子项都会自动分配给该属性。
另请参阅 contentItem 。
contentItem : Item [read-only]
该属性用于存储窗口内容项。
该内容项位于background 项之上,位于menuBar 、header 和footer 项之下。
从 Qt 6.9 开始,ApplicationWindow 会针对窗口报告的任何safe area margins ,自动为 contentItem 添加内边距。若要覆盖该内边距,请使用相应的内边距属性。
另请参阅 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 [since 6.9]
该属性存储窗口内容项的左侧填充值。除非显式设置,否则该值反映窗口的safe area margins 。
该属性在 Qt 6.9 中引入。
另请参阅 bottomPadding 、topPadding 和rightPadding 。
locale : Locale
该属性存储窗口的区域设置。
默认区域设置取决于系统环境。您可以在加载任何 QML 之前,通过调用 `QLocale::setDefault()` 来设置默认区域设置。
ApplicationWindow 将区域设置传播到子控件。如果更改窗口的区域设置,该区域设置将传播到窗口中的所有子控件,并覆盖系统的默认区域设置。
另请参阅 Control::locale 。
menuBar : Item [since QtQuick.Controls 2.3 (Qt 5.10)]
该属性用于控制窗口的菜单栏。菜单栏位于窗口顶部(标题栏上方),其宽度会根据窗口宽度进行调整。默认值为null 。
ApplicationWindow {
menuBar: MenuBar {
// ...
}
}该属性在 QtQuick.Controls 2.3(Qt 5.10)中引入。
另请参阅 header 、footer 和MenuBar 。
rightPadding : real [since 6.9]
该属性保存窗口内容项的右侧填充值。除非显式设置,否则该值反映窗口的safe area margins 。
该属性在 Qt 6.9 中引入。
另请参阅 bottomPadding 、leftPadding 以及topPadding 。
topPadding : real [since 6.9]
该属性保存窗口内容项的顶部内边距。除非显式设置,否则该值反映窗口的safe area margins 。
该属性在 Qt 6.9 中引入。
另请参阅 bottomPadding 、leftPadding 以及rightPadding 。
相关属性文档
ApplicationWindow.activeFocusControl : Control [read-only attached]
此附加属性保存当前具有活动焦点的控件,如果没有任何控件具有活动焦点,则该属性值为null 。该属性可附加到任何项目上。如果该项目不在窗口中,或者窗口没有活动焦点,则该属性值为null 。
另请参阅 Window::activeFocusItem 和Attached ApplicationWindow Properties 。
ApplicationWindow.contentItem : Item [read-only attached]
此附加属性用于存储窗口内容项。该属性可附加到任何项上。如果该项不在ApplicationWindow 中,则其值为null 。
另请参阅 Attached ApplicationWindow Properties 。
ApplicationWindow.footer : Item [read-only attached]
此附加属性用于存储窗口页脚项。该属性可附加到任何项上。如果该项不在ApplicationWindow 中,或者窗口没有页脚项,则其值为null 。
另请参阅 Attached ApplicationWindow Properties 。
ApplicationWindow.header : Item [read-only attached]
此附加属性用于存储窗口标题项。该属性可附加到任何项上。如果该项不在ApplicationWindow 中,或者窗口没有标题项,则其值为null 。
另请参阅 Attached ApplicationWindow Properties 。
ApplicationWindow.menuBar : Item [read-only attached, since QtQuick.Controls 2.3 (Qt 5.10)]
此附加属性用于存储窗口菜单栏。该属性可附加到任何项目上。如果该项目不在ApplicationWindow 中,或者窗口没有菜单栏,则该属性的值为null 。
该属性于 QtQuick.Controls 2.3(Qt 5.10)中引入。
另请参阅 Attached ApplicationWindow Properties 。
ApplicationWindow.window : ApplicationWindow [read-only attached]
此附加属性用于存储应用程序窗口。该属性可附加到任何项目上。如果该项目不在ApplicationWindow 中,则其值为null 。
© 2026 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.