MenuBar QML Type

Provides a window menu bar. 更多...

import 语句: import QtQuick.Controls 2.15
Since: Qt 5.10
继承:

容器

特性

方法

详细描述

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 ,和 take menus dynamically. The menus in a menu bar can be accessed using menuAt() .

另请参阅 Customizing MenuBar , Menu , MenuBarItem , 菜单控件 ,和 Focus Management in Qt Quick Controls .

特性文档编制

contentHeight : real

This property holds the content height. It is used for calculating the total implicit height of the menu bar.

注意: This property is available in MenuBar since QtQuick .Controls 2.3 (Qt 5.10), but it was promoted to the Container base type in QtQuick .Controls 2.5 (Qt 5.12).

该特性在 QtQuick.Controls 2.3 (Qt 5.10) 引入。

另请参阅 Container::contentHeight .

contentWidth : real

This property holds the content width. It is used for calculating the total implicit width of the menu bar.

注意: This property is available in MenuBar since QtQuick .Controls 2.3 (Qt 5.10), but it was promoted to the Container base type in QtQuick .Controls 2.5 (Qt 5.12).

该特性在 QtQuick.Controls 2.3 (Qt 5.10) 引入。

另请参阅 Container::contentWidth .

delegate : Component

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

另请参阅 MenuBarItem .

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.

方法文档编制

void addMenu ( Menu menu )

添加 menu to the end of the list of menus.

void insertMenu ( int index , Menu menu )

插入 menu at index .

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

void removeMenu ( Menu menu )

Removes and destroys the specified menu .

Menu takeMenu ( int index )

Removes and returns the menu at index .

注意: The ownership of the item is transferred to the caller.