Menu QML Type

Provides a menu component for use as a context menu, popup menu, or as part of a menu bar. 更多...

import 語句: import QtQuick.Controls 1.4
Since: Qt 5.1

特性

信號

方法

詳細描述

Menu {
    title: "Edit"
    MenuItem {
        text: "Cut"
        shortcut: "Ctrl+X"
        onTriggered: ...
    }
    MenuItem {
        text: "Copy"
        shortcut: "Ctrl+C"
        onTriggered: ...
    }
    MenuItem {
        text: "Paste"
        shortcut: "Ctrl+V"
        onTriggered: ...
    }
    MenuSeparator { }
    Menu {
        title: "More Stuff"
        MenuItem {
            text: "Do Nothing"
        }
    }
}
					

The main uses for menus:

  • 作為 top-level menu in a MenuBar
  • 作為 submenu inside another menu
  • as a standalone or context menu

Note that some properties, such as 被啓用 , text ,或 iconSource , only make sense in a particular use case of the menu.

另請參閱 MenuBar , MenuItem ,和 MenuSeparator .

特性文檔編製

enabled : bool

Whether the menu is enabled, and responsive to user interaction as a submenu. Its value defaults to true .

iconName : string

Sets the icon name for the menu icon. This will pick the icon with the given name from the current theme. Only works as a submenu.

Its value defaults to an empty string.

另請參閱 iconSource .

iconSource : url

Sets the icon file or resource url for the menu icon as a submenu. Defaults to an empty URL.

另請參閱 iconName .

[default] items : list < 對象 >

The list of items in the menu.

Menu only accepts objects of type Menu , MenuItem ,和 MenuSeparator as children. It also supports Instantiator objects as long as the insertion is being done manually using insertItem() .

Menu {
    id: recentFilesMenu
    Instantiator {
        model: recentFilesModel
        MenuItem {
            text: model.fileName
        }
        onObjectAdded: recentFilesMenu.insertItem(index, object)
        onObjectRemoved: recentFilesMenu.removeItem(object)
    }
    MenuSeparator {
        visible: recentFilesModel.count > 0
    }
    MenuItem {
        text: "Clear menu"
        enabled: recentFilesModel.count > 0
        onTriggered: recentFilesModel.clear()
    }
}
									

Note that in this case, the index parameter passed to insertItem() is relative to the position of the Instantiator in the menu, as opposed to absolute position in the menu.

另請參閱 MenuItem and MenuSeparator .

style : Component

The style Component for this control.

This QML property was introduced in QtQuick.Controls.Styles 1.2.

另請參閱 MenuStyle .

title : string

Title for the menu as a submenu or in a menubar.

Mnemonics are supported by prefixing the shortcut letter with &. For instance, "\&File" will bind the Alt-F shortcut to the "File" menu. Note that not all platforms support mnemonics.

Its value defaults to an empty string.

type : enumeration

This property is read-only and constant, and its value is type .

visible : bool

Whether the menu should be visible as a submenu of another Menu, or as a menu on a MenuBar . Its value defaults to true .

注意: This has nothing to do with the actual menu pop-up window being visible. Use aboutToShow() and aboutToHide() if you need to know when the pop-up window will be shown or hidden.


信號文檔編製

aboutToHide ()

此信號被發射僅僅在菜單對用戶隱藏之前。

This QML signal was introduced in QtQuick.Controls 1.4.

另請參閱 aboutToShow() .

aboutToShow ()

此信號被發射僅僅在菜單對用戶展示之前。

This QML signal was introduced in QtQuick.Controls 1.4.

另請參閱 aboutToHide() .


方法文檔編製

MenuItem addItem ( string text )

Adds an item to the menu. Returns the newly created MenuItem .

另請參閱 insertItem() .

Menu addMenu ( string title )

Adds a submenu to the menu. Returns the newly created Menu .

另請參閱 insertMenu() .

void addSeparator ()

Adds a separator to the menu.

另請參閱 insertSeparator() .

void insertItem ( int before , object item )

插入 item at the index before in the current menu. In this case, item can be either a MenuItem MenuSeparator ,或 Menu .

另請參閱 removeItem() .

MenuItem insertItem ( int before , string title )

Creates and inserts an item with title title at the index before in the current menu. Returns the newly created MenuItem .

另請參閱 addItem() .

MenuItem insertMenu ( int before , string title )

Creates and inserts a submenu with title title at the index before in the current menu. Returns the newly created Menu .

另請參閱 addMenu() .

void insertSeparator ( int before )

Creates and inserts a separator at the index before in the current menu.

另請參閱 addSeparator() .

Opens this menu under the mouse cursor. It can block on some platforms, so test it accordingly.

void removeItem ( item )

移除 item from the menu. In this case, item can be either a MenuItem MenuSeparator ,或 Menu .

另請參閱 insertItem() .

版權所有  © 2014-2026 樂數軟件    

工業和信息化部: 粵ICP備14079481號-1