ToolBar QML Type

上下文敏感控件的容器。更多

Import Statement: import QtQuick.Controls
Inherits:

Pane

属性

详细说明

工具栏(ToolBar)是应用程序范围内的上下文敏感操作和控件(如导航按钮和搜索栏)的容器。工具栏通常用作headerApplicationWindowfooter

工具栏本身不提供布局,但需要您对其内容进行定位,例如通过创建RowLayout 。如果工具栏中只使用了一个项目,它将调整大小以适应其所包含项目的隐含大小。因此,它特别适合与布局一起使用。

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,自定义工具栏容器控件

属性文档

position : enumeration

该属性用于保存工具栏的位置。

注: 如果工具栏被指定为ApplicationWindowPage 的页眉或页脚,则会自动设置适当的位置。

可能的值:

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

默认值与样式有关。

另请参阅 ApplicationWindow::header,ApplicationWindow::footer,Page::header, 和Page::footer


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