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" },
        ];
    }
}