Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.9.0
-
None
-
Qt: qt-opensource-linux-x64-5.9.0
Build host: Ubuntu 64bit
-
d091c75c0b953a8b91c57f075769036bd09ae4c2
Description
The default value for Menu's closePolicy, inherited from Popup should be Popup.CloseOnEscape | Popup.CloseOnPressOutside (17 = 16 + 1), according to docs https://doc.qt.io/qt-5/qml-qtquick-controls2-popup.html#closePolicy-prop.
But the actual value of Menu's closePolicy is Popup.CloseOnEscape | Popup.CloseOnPressOutside | Popup.CloseOnReleaseOutside (21 = 16 + 1 + 4).
If a Menu has the Popup.CloseOnReleaseOutside property set and is opened when the onPressAndHold event is triggered by some other controls (like ListView's ItemDelegates below), then the Menu gets closed immediately after it is opened. Given that onPressAndHold is used in many touch-based UIs for opening menus, this behavior is strange.
NOTE 1: Is this really a bug or a new feature? Should we explicitely exclude Popup.CloseOnReleaseOutside from Menu's closePolicy to make it work with onPressAndHold events?
NOTE 2: Using a custom implementation of onPressAndHold, because it seems to be broken on Linux (see QTBUG-61393).
Steps to reproduce:
1) Press-and-hold (do not release the mouse button yet) ListView's Item1 - the menu is opened.
2) Release the mouse button - the menu is still open (the bug should happen already here? But for some reason it happens later - see step 5).
3) Click somewhere outside of the menu - the menu is closed.
4) Press-and-hold (do not release the mouse button yet) ListView's Item2 - the menu is opened.
5) Release the mouse button - the menu is closed. Expected behaviur: the menu should still be open.
import QtQuick 2.8 import QtQuick.Window 2.2 import QtQuick.Controls 2.2 Window { visible: true width: 640 height: 480 Menu { id: menu MenuItem { text: "Menu Item" } Component.onCompleted: console.log("menu closePolicy:", closePolicy) // Setting closePolicy to not include Popup.CloseOnReleaseOutside fixes // the problem with menu being closed prematurely on mouse release. // closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside } Popup { Component.onCompleted: console.log("popup closePolicy:", closePolicy) } ListView { anchors.right: parent.right model: 3 width: 100 height: 300 delegate: ItemDelegate { text: "item" + index background: Rectangle { border.width: 1 } MouseArea { id: mouseArea anchors.fill: parent signal clickedCustom(int button) signal pressAndHoldCustom(int button) onPressAndHoldCustom: menu.open() Timer { id: timer interval: 700 onTriggered: mouseArea.pressAndHoldCustom(mouseArea.pressedButtons) } onPressed: timer.restart() onReleased: if (timer.running) { timer.stop() clickedCustom(mouse.button) } } } } } // Output // qml: popup closePolicy: 17 // qml: menu closePolicy: 21
Attachments
For Gerrit Dashboard: QTBUG-61608 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
198817,2 | QQuickMenu: fix press-and-hold support | 5.9 | qt/qtquickcontrols2 | Status: MERGED | +2 | 0 |