本页内容

ToolBar QML Type

用于上下文相关控件的容器。更多...

Import Statement: import QtQuick.Controls
Inherits:

Pane

属性

详细说明

ToolBar 是一个包含全局和上下文相关操作及控件(例如导航按钮和搜索框)的容器。ToolBar 通常用作ApplicationWindow 的header 或footer 。

ToolBar 本身不提供布局,而是需要您自行定位其内容,例如通过创建RowLayout 来实现。如果 ToolBar 中仅包含一个项目,它会自动调整大小以适应所包含项目的隐式尺寸。这使其特别适合与布局配合使用。

包含按钮和其他控件的工具栏

ApplicationWindow {
    visible:true

    header: ToolBar {
        RowLayout {
            anchors.fill: parent
            ToolButton {
                text: qsTr("‹")
                onClicked: stack.pop()
            }
            Label {
                text: "Title"
                elide: Label.ElideRight
                horizontalAlignment: Qt.AlignHCenter
                verticalAlignment: Qt.AlignVCenter
                Layout.fillWidth: true
            }
            ToolButton {
                text: qsTr("⋮")
                onClicked: menu.open()
            }
        }
    }

    StackView {
        id: stack
        anchors.fill: parent
    }
}

另请参阅 ApplicationWindow 、ToolButton 、自定义 ToolBar 以及容器控件。

属性文档

position : enumeration

该属性用于指定工具栏的位置。

注意:如果 将工具栏指定为ApplicationWindow 或Page 的页眉或页脚,系统会自动设置相应的位置。

可能的取值:

常量描述
ToolBar.Header工具栏位于顶部,作为窗口或页面页眉。
ToolBar.Footer工具栏位于底部,作为窗口或页面的页脚。

默认值因样式而异。

另请参阅 ApplicationWindow::header 、ApplicationWindow::footer 、Page::header 以及Page::footer 。

© 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.