ContextMenu

ContextMenu displays a list of items with a default item delegate inside of a PopupWindow.

Properties

  • model (in [ListViewItem]): The model of items.
  • min-menu-width (in length): Defines the minimum width of the context menu.
  • offset-x (in length): Defines the x offset of the context menu.
  • offset-y (in length): Defines the y offset of the context menu.
  • has-focus: (out bool): Set to true when the context menu currently has the focus.
  • current-item (in_out int): The index of the currently active item. -1 mean none is selected, which is the default.

Callbacks

  • item-clicked(/* row */ int): Emitted when an item was clicked.
  • close(): Emitted when the context menu is closed.

Functions

  • show() Call this function show the context menu.
  • close() Call this function close the context menu.
  • show-and-focus() Call this function show and focus the context menu.

Example

import { ContextMenu, Button } from "@coop/lib.slint";

export component Example inherits Window {
    width: 200px;
    height: 25px;

    Button {
        clicked => {
            i-context-menu.show();
        }

        text: "Open context menu";
    }

    i-context-menu := ContextMenu {
        x: 50px;
        y: 50px;

        model: [
            { text: "Item 1" },
            { text: "Item 2" },
            { text: "Item 2" },
        ];
    }
}