MenuBar QML Type
原生菜单栏。更多...
| Import Statement: | import Qt.labs.platform |
| Inherits: |
属性
方法
- void addMenu(Menu menu)
- void clear()
- void insertMenu(int index, Menu menu)
- void removeMenu(Menu menu)
详细说明
MenuBar 类型为原生平台的菜单栏提供了 QML API。

菜单栏由一组下拉菜单组成。
MenuBar {
id: menuBar
Menu {
id: fileMenu
title: qsTr("File")
// ...
}
Menu {
id: editMenu
title: qsTr("&Edit")
// ...
}
Menu {
id: viewMenu
title: qsTr("&View")
// ...
}
Menu {
id: helpMenu
title: qsTr("&Help")
// ...
}
}MenuBar 目前可在以下平台上使用:
- macOS
- Android
- Linux(仅支持提供全局 D-Bus 菜单栏的桌面环境)
- Windows
注意: Qt.labs 模块中的类型在未来版本中不保证保持兼容性。
另请参阅 Menu 。
属性文档
data : list<QtObject> [default]
此默认属性包含所有被声明为菜单栏子对象的对象列表。data 属性包含非Menu 实例的对象,例如Timer 和QtObject 。
另请参阅 menus 。
menus : list<Menu>
该属性保存了菜单栏中的菜单列表。
window : Window
该属性存储菜单栏的窗口。
除非显式设置,否则系统会通过遍历 QML 父对象来自动确定窗口,直到找到具有窗口的 `Window ` 或 `Item ` 为止。
方法文档
void addMenu(Menu menu)
在菜单栏末尾添加一个menu 。
void clear()
从菜单栏中移除所有菜单。
void insertMenu(int index, Menu menu)
在菜单栏中指定位置(index )插入一个“menu ”。
void removeMenu(Menu menu)
从菜单栏中移除menu 。
© 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.