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
- 安卓
- Linux(仅适用于提供全局 D-Bus 菜单栏的桌面环境)
- Windows
注: Qt.lab 模块中的类型不保证在未来版本中保持兼容。
另请参阅 Menu 。
属性文档
data : list<QtObject> [default]
该默认属性包含所有声明为菜单子对象的对象列表。数据属性包括不是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.