IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

Menu QML Type

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

This type was introduced in Qt 5.1.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

Menu QML Type▲

Detailed Description▲

Image non disponible
 
Sélectionnez
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:

  • as a top-level menu in a MenuBar

  • as a submenu inside another menu

  • as a standalone or context menu

Note that some properties, such as enabled, text, or iconSource, only make sense in a particular use case of the menu.

See Also▲

Property Documentation▲

 

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.

See Also▲

See also iconSource

iconSource : url▲

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

See Also▲

See also iconName

items : list<Object>▲

The list of items in the menu.

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

 
Sélectionnez
Menu {
    id: recentFilesMenu

    Instantiator {
        model: recentFilesModel
        MenuItem {
            text: model.fileName
        }
        onObjectAdded: recentFilesMenu.insertItem(index, object)
        onObjectRemoved: recentFilesMenu.removeItem(object)
    }

    MenuSeparator {
        visible: recentFilesModel.count &gt; 0
    }

    MenuItem {
        text: "Clear menu"
        enabled: recentFilesModel.count &gt; 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.

See Also▲

[since QtQuick.Controls.Styles 1.2] style : Component▲

The style Component for this control.

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

See Also▲

See also 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.

Signal Documentation▲

 

[since QtQuick.Controls 1.4] aboutToHide()▲

This signal is emitted just before the menu is hidden from the user.

The corresponding handler is onAboutToHide.

This signal was introduced in QtQuick.Controls 1.4.

See Also▲

See also aboutToShow()

[since QtQuick.Controls 1.4] aboutToShow()▲

This signal is emitted just before the menu is shown to the user.

The corresponding handler is onAboutToShow.

This signal was introduced in QtQuick.Controls 1.4.

See Also▲

See also aboutToHide()

Method Documentation▲

 

MenuItem addItem(string text)▲

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

See Also▲

See also insertItem()

Menu addMenu(string title)▲

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

See Also▲

See also insertMenu()

void addSeparator()▲

Adds a separator to the menu.

See Also▲

See also insertSeparator()

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.

See Also▲

See also addItem()

void insertItem(int before, object item)▲

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

See Also▲

See also removeItem()

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.

See Also▲

See also addMenu()

void insertSeparator(int before)▲

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

See Also▲

See also addSeparator()

void popup()▲

void removeItem(item)▲

Removes the item from the menu. In this case, item can be either a MenuItem, a MenuSeparator, or a Menu.

See Also▲

See also insertItem()

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+