Andrey Epifantsev
Andrey Epifantsev

Reputation: 1104

MenuItem subMenu property: how to assign it?

I read MenuItem documentation: https://doc.qt.io/qt-5/qml-qtquick-controls2-menuitem.html

MenuItem has property subMenu but this property is read only. And I cannot find any other properties or methods to add sub menu to MenuItem.

How to add sub menu to MenuItem?

I need to handle MenuItem signal triggered and have submenu simultaneously. So using Menu class instead of MenuItem is not a solution of my problem because it does not have signal triggered.

Upvotes: 0

Views: 525

Answers (1)

Jan Win
Jan Win

Reputation: 147

from: https://www3.sra.co.jp/qt/relation/doc/qtlabsplatform/qml-qt-labs-platform-menu.html#submenus

To create submenus, declare a Menu as a child of another Menu:

Menu {
title: qsTr("Edit")

Menu {
    title: qsTr("Advanced")

    MenuItem {
        text: qsTr("Auto-indent Selection")
        onTriggered: autoIndentSelection()
    }

    MenuItem {
        text: qsTr("Rewrap Paragraph")
        onTriggered: rewrapParagraph()
    }
}
}

SubMenu

Upvotes: 1

Related Questions