- Qt 6.10
- Qt Quick Controls
- QML Types
- MenuBar
- Qt 6.10.2 Reference Documentation

# MenuBar QML Type

Provides a window menu bar. More...

Import Statement: | `import QtQuick.Controls`
Inherits: | Container

- List of all members, including inherited members

## Properties

- delegate : Component
- menus : list<Menu>

## Methods

- void addMenu(Menu menu)
- void insertMenu(int index, Menu menu)
- Menu menuAt(int index)
- void removeMenu(Menu menu)
- Menu takeMenu(int index)

## Detailed Description

MenuBar consists of drop-down menus, and is normally located at the top edge of the window.

     ApplicationWindow {
         id: window
         width: 320
         height: 260
         visible: true

         menuBar: MenuBar {
             Menu {
                 title: qsTr("&File")
                 Action { text: qsTr("&New...") }
                 Action { text: qsTr("&Open...") }
                 Action { text: qsTr("&Save") }
                 Action { text: qsTr("Save &As...") }
                 MenuSeparator { }
                 Action { text: qsTr("&Quit") }
             }
             Menu {
                 title: qsTr("&Edit")
                 Action { text: qsTr("Cu&t") }
                 Action { text: qsTr("&Copy") }
                 Action { text: qsTr("&Paste") }
             }
             Menu {
                 title: qsTr("&Help")
                 Action { text: qsTr("&About") }
             }
         }
     }

Typically, menus are statically declared as children of the menu bar, but MenuBar also provides API to add, insert, remove, and take menus dynamically. The menus in a menu bar can be accessed using menuAt().

## Native menu bars

Since Qt 6.8, a MenuBar is implemented as a native menu bar on macOS. As a result, all Menus, MenuItems and MenuBarItems within a MenuBar will also be native. While this has the advantage that everything will look native, it also comes with the disadvantage that the delegates set on the mentioned controls will not be used for rendering. If a native MenuBar is not wanted, you can set QGuiApplication::setAttribute(Qt::AA_DontUseNativeMenuBar) to disable it.

See also Customizing MenuBar, Menu, MenuBarItem, Menu Controls, and Focus Management in Qt Quick Controls.

## Property Documentation

delegate : Component

This property holds the component that is used to create menu bar items to present menus in the menu bar.

See also MenuBarItem.

menus : list<Menu>

This property holds the list of menus.

The list contains all menus that have been declared in QML as children of the menu bar, and also menus that have been dynamically added or inserted using the addMenu() and insertMenu() methods, respectively.

## Method Documentation

void addMenu(Menu menu)

Adds menu to the end of the list of menus.

void insertMenu(int index, Menu menu)

Inserts menu at index.

Menu menuAt(int index)

Returns the menu at index, or `null` if it does not exist.

void removeMenu(Menu menu)

Removes specified menu. If the menu is open, it will first be dismissed. The menu will eventually be deleted by the garbage collector when the application no longer holds any QML references to it.

Menu takeMenu(int index)

Removes and returns the menu at index. If the menu is open, it will first be dismissed. The menu will eventually be deleted by the garbage collector when the application no longer holds any QML references to it.