ConvergentContextMenu QML Type

Menu popup that appears as a tradional menu on desktop and as a bottom drawer mobile. More...

Import Statement: import org.kde.kirigamiaddons.labs.components
Inherits:

Item

Properties

Signals

Methods

Detailed Description

ConvergentContextMenu uses abstract QtQuick.Controls.Action and Kirigami.Action to build the traditional menu on desktop and the bottom drawer on mobile. Most properties of Kirigami.Action are supported including nested actions.

import QtQuick.Controls as Controls
import org.kde.kirigami as Kirigami
import org.kde.kirigamiaddons.components as Components
import org.kde.kirigamiaddons.formcard as FormCard

Components.ConvergentContextMenu {
    id: root

    headerContentItem: RowLayout {
        spacing: Kirigami.Units.smallSpacing
        Kirigami.Avatar { ... }

        Kirigami.Heading {
            level: 2
            text: "Room Name"
        }
    }

    Controls.Action {
        text: i18nc("@action:inmenu", "Simple Action")
    }

    Kirigami.Action {
        text: i18nc("@action:inmenu", "Nested Action")

        Controls.Action { ... }

        Controls.Action { ... }

        Controls.Action { ... }
    }

    Kirigami.Action {
        text: i18nc("@action:inmenu", "Nested Action with Multiple Choices")

        Kirigami.Action {
            text: i18nc("@action:inmenu", "Follow Global Settings")
            checkable: true
            autoExclusive: true // Since KF 6.10
        }

        Kirigami.Action {
            text: i18nc("@action:inmenu", "Enabled")
            checkable: true
            autoExclusive: true // Since KF 6.10
        }

        Kirigami.Action {
            text: i18nc("@action:inmenu", "Disabled")
            checkable: true
            autoExclusive: true // Since KF 6.10
        }
    }

    // custom FormCard delegate only supported on mobile
    Kirigami.Action {
        visible: Kirigami.Settings.isMobile
        displayComponent: FormCard.FormButtonDelegate { ... }
    }
}

When creating a menu for a ListView, avoid creating a ConvergentContextMenu for each delegate and instead create a global ConvergentContextMenu for the ListView or use a Component and dynamically instantiate the context menu on demand:

import QtQuick
import QtQuick.Controls as Controls
import org.kde.kirigamiaddons.components as Addons

ListView {
    model: 10
    delegate: Controls.ItemDelegate {
        text: index

        function openContextMenu(): void {
            const item = menu.createObject(Controls.Overlay.overlay, {
                index,
            });
            item.popup();
        }

        onPressAndHold: openContextMenu()

        // Since Qt 6.9
        Controls.ContextMenu.onRequested: (position) => openContextMenu()

        // Before Qt 6.9
        TapHandler {
            acceptedButtons: Qt.RightButton
            onSingleTapped: (eventPoint, button) => {
                openContextMenu();
            }
        }
    }

    Component {
        id: menu

        Addons.ConvergentContextMenu {
            required property int index

            Controls.Action {
                text: i18nc("@action:inmenu", "Action 1")
            }

            Kirigami.Action {
                text: i18nc("@action:inmenu", "Action 2")

                Controls.Action {
                    text: i18nc("@action:inmenu", "Sub-action")
                }
            }
        }
    }
}

Property Documentation

actions : list<Action> [default]

This property holds the list of actions.

This can be either a traditional QtQuick.Controls.Action or a Kirigami.Action with sub actions.


headerContentItem : Item

Optional item which will be displayed as header of the internal ButtonDrawer.

Note: This is only displayed on the first level of the ContextMenu mobile mode.


opened : bool

This property holds whether the popup is fully open.

Note: Setting this property yourself does nothing. You must open the popup using popup().


Signal Documentation

closed()

Emitted when the context menu is closed.

Note: The corresponding handler is onClosed.


Method Documentation

close()

Close the context menu.


Open the context menu.