MenuItem QML Type

MenuItem provides an item to add in a menu or a menu bar. 更多...

import 語句: import QtQuick.Controls 1.4

特性

信號

方法

詳細描述

Menu {
    text: "Edit"
    MenuItem {
        text: "Cut"
        shortcut: "Ctrl+X"
        onTriggered: ...
    }
    MenuItem {
        text: "Copy"
        shortcut: "Ctrl+C"
        onTriggered: ...
    }
    MenuItem {
        text: "Paste"
        shortcut: "Ctrl+V"
        onTriggered: ...
    }
}
					

另請參閱 MenuBar , Menu , MenuSeparator ,和 動作 .

特性文檔編製

action : 動作

The action bound to this menu item. It will provide values for all the properties of the menu item. However, it is possible to override the action's text , iconSource ,和 iconName properties by just assigning these properties, allowing some customization.

In addition, the menu item triggered() and toggled() signals will not be emitted. Instead, the action triggered() and toggled() signals will be.

默認為 null , meaning no action is bound to the menu item.

checkable : bool

Whether the menu item can be checked, or toggled. Defaults to false .

另請參閱 checked .

checked : bool

If the menu item is checkable, this property reflects its checked state. Defaults to false .

另請參閱 checkable and Action::toggled .

enabled : bool

Whether the menu item is enabled, and responsive to user interaction. Defaults to true .

exclusiveGroup : ExclusiveGroup

If a menu item is checkable, an ExclusiveGroup can be attached to it. All the menu items sharing the same exclusive group, and by extension, any 動作 sharing it, become mutually exclusive selectable, meaning that only the last checked menu item will actually be checked.

默認為 null , meaning no exclusive behavior is to be expected.

另請參閱 checked and checkable .

iconName : string

Sets the icon name for the MenuItem icon. This will pick the icon with the given name from the current theme. Overrides the item's bound action iconName property. Defaults to an empty string.

注意: This property requires QApplication .

另請參閱 iconSource and Action::iconName .

iconSource : url

Sets the icon file or resource url for the MenuItem icon. Overrides the item's bound action iconSource property. Defaults to an empty URL.

另請參閱 iconName and Action::iconSource .

shortcut : keysequence

Shortcut bound to the menu item. The keysequence can be a string or a 標準鍵 .

Defaults to an empty string.

MenuItem {
    id: copyItem
    text: qsTr("&Copy")
    shortcut: StandardKey.Copy
}
													

另請參閱 Action::shortcut .

text : string

Text for the menu item. Overrides the item's bound action text 特性。

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

Defaults to an empty string.

另請參閱 Action::text .

[read-only] type : enumeration

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

visible : bool

Whether the menu item should be visible. Defaults to true .


信號文檔編製

toggled ( checked )

Emitted whenever a menu item's checked property changes. This usually happens at the same time as triggered .

相應處理程序是 onToggled .

另請參閱 checked , triggered , Action::triggered ,和 Action::toggled .

triggered ()

Emitted when either the menu item or its bound action have been activated.

相應處理程序是 onTriggered .

另請參閱 trigger() , Action::triggered ,和 Action::toggled .


方法文檔編製

void trigger ()

Manually trigger a menu item. Will also trigger the item's bound action.

另請參閱 triggered and Action::trigger() .