Sailfish OS
  • Info
  • User Experience
  • Cases
  • Community
  • Developers
  • Contact
  • Get Sailfish OS
Select Page
  • Info
  • User Experience
  • Cases
  • Community
  • Developers
  • Contact
  • Get Sailfish OS

API Documentation

Documentation for developing SailfishOS applications
  • API Documentation
  • Libsailfishapp
  • Sailfish Silica
    • Documentation
    • Icon Reference
  • Sailfish Components
    • Sailfish Accounts
    • Sailfish Bluetooth
    • Sailfish Contacts
    • Sailfish Crypto
    • Sailfish Gallery
    • Sailfish Media
    • Sailfish Pickers
    • Sailfish Secrets
    • Sailfish Share
    • Sailfish Telephony
    • Sailfish Webview
    • Amber Web Authorization
    • Amber MPRIS
  • Nemo QML Plugins
    • Configuration
    • Contacts
    • D-Bus
    • Keepalive
    • Notifications
    • Thumbnailer
  • Sailfish Middleware
    • MDM Framework
    • MDM Policy Framework
    • User Manager Daemon
  • API Documentation
  • Libsailfishapp
  • Sailfish Silica
    • Documentation
    • Icon Reference
  • Sailfish Components
    • Sailfish Accounts
    • Sailfish Bluetooth
    • Sailfish Contacts
    • Sailfish Crypto
    • Sailfish Gallery
    • Sailfish Media
    • Sailfish Pickers
    • Sailfish Secrets
    • Sailfish Share
    • Sailfish Telephony
    • Sailfish Webview
    • Amber Web Authorization
    • Amber MPRIS
  • Nemo QML Plugins
    • Configuration
    • Contacts
    • D-Bus
    • Keepalive
    • Notifications
    • Thumbnailer
  • Sailfish Middleware
    • MDM Framework
    • MDM Policy Framework
    • User Manager Daemon

Contents

  • Properties
  • Signals
  • Methods
  • Detailed Description

ContextMenu QML Type

Provides a context-specific menu More...

Import Statement: import Sailfish.Silica 1.0
  • List of all members, including inherited members
  • Obsolete members

Properties

  • active : bool
  • closeOnActivation : bool
  • container : Item
  • hasContent : bool

Signals

  • closed()
  • onActivated(int index)

Methods

  • close()
  • open(Item item)

Detailed Description

The ContextMenu type provides a menu for use in context-specific situations.

A ContextMenu is a pop-up menu that shows beneath a specified item when activated with the show() function. Menu options are specified through MenuItem children.

Context menus are commonly used to display menu options for individual entries within a list. Here is an example that uses the ListItem menu property to show a context menu for each individual list item when the item's press-and-hold gesture is activated:

 import QtQuick 2.2
 import Sailfish.Silica 1.0

 Page {
     SilicaListView {
         anchors.fill: parent

         model: ListModel {
             id: listModel
             Component.onCompleted: {
                 for (var i=0; i<10; i++) {
                     append({"name": "Item " + i})
                 }
             }
         }

         delegate: ListItem {
             width: ListView.view.width

             Label {
                 id: label
                 text: model.name
                 anchors.centerIn: parent
             }

             menu: ContextMenu {
                 MenuItem {
                     text: "Toggle bold font"
                     onClicked: label.font.bold = !label.font.bold
                 }
                 MenuItem {
                     text: "Remove"
                     onClicked: listModel.remove(model.index)
                 }
             }
         }
     }
 }

Warning: The ContextMenu internally adjusts its height whenever it is opened or closed. Therefore, the height should not be explicitly set or changed, and the menu should not be anchored at both its top and bottom edges, else the menu will no longer open and close correctly.

See also MenuItem, PullDownMenu, and PushUpMenu.

Property Documentation

active : bool

This property holds whether the menu is currently shown.


closeOnActivation : bool

If set to true, the menu will automatically close if a child MenuItem is clicked.

The default value is true.


container : Item

This property holds a parent container to be used for calculating how the flickable's contentY should be changed.

Normally, when the menu is opened within a vertically-scrolling flickable, the flickable's contentY moves upwards if this is necessary to make the whole menu visible within the flickable. If the container is set, then its bounds are also taken into account when determining whether the contentY should be moved. This useful if the menu should extend beyond the bounds of the flickable and into the parent container.

The default value is null.


hasContent : bool

This property holds whether the menu has content to be shown when opened; if false, the context menu will not open.

The default value is true if the menu item has any child items. Note that this heuristic will be incorrect if there are only non-visible children in the menu, such as an empty Repeater.


Signal Documentation

closed()

Called when the close animation has finished.


onActivated(int index)

Called when a child MenuItem is clicked. The index value is the index of the menu item within this menu.


Method Documentation

close()

Closes the menu.

See also open.


open(Item item)

Shows the menu, anchored to the bottom of the specified parent item. If the ContextMenu is within a flickable view it will adjust the view position to ensure that the menu is completely visible.

See also close.


  • Legal
  • Contact Us
  • Jollyboys Ltd © 2024

  • Facebook
  • Twitter
  • Mastodon
  • YouTube
  • LinkedIn