Not to close Menu on MenuItem Click
-
Hi! I have a button with a menu like this:
Button { tooltip: qsTr("Filters") style: ButtonStyle { background: Rectangle { implicitWidth: TextSingleton.pixelDeviceRatio * 24 implicitHeight: TextSingleton.pixelDeviceRatio * 24 x: control.pressed ? -1 : 0 y: control.pressed ? 1 : 0 color: "transparent" Image { anchors.fill: parent source: control.hovered ? "qrc:///img/res/img/filters_w_hover.png" : "qrc:///img/res/img/filters_w.png" mipmap: true } } } menu: Menu { id: filtersMenu MenuItem { id: menuItemTitle text: qsTr("Title") checkable: true checked: false } MenuItem { id: menuItemDescription text: qsTr("Description") checkable: true checked: false } } }
I would like the menu does not close when the items are clicked, to be able to select some filters without having to open the menu again.
-
Hi
All normal main menus ever known to man, has always closed when you choose an item.
So are u sure a menu is the right way of selecting filters ?
:) -
@mrjj For example, in many programs, when you are choosing toolbars, the rightmenu does not close what allows to choose some of them at once. I was thinking in implement the same.
From your answer... I suppose there's no way to do it with Menu component, doesn't it? -
Just changing
MenuItem
toCheckBox
does the job. Menu stays as long as you clicking CheckBox items:Menu { CheckBox { text: "Item A" checkable: true checked: false onCheckedChanged: { console.debug("item A", checked) } } CheckBox { text: "Item B" checkable: true checked: false onCheckedChanged: { console.debug("item B", checked) } } }
This topic is still high in search results, so I think it would be helpful to post correct answer. Despite question is old it is still useful.