diff options
author | Filippo Cucchetto <filippocucchetto@gmail.com> | 2015-12-05 08:58:01 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-12-07 13:41:34 +0000 |
commit | 12f699a0a66055b70acfcc4f6c957cebf19f4504 (patch) | |
tree | 540acceac6fef55a6dcdb18766c98f8a040e699a | |
parent | a3ba1a532f92a933141d4671ce644053a0cb6fea (diff) | |
download | qtquickcontrols-12f699a0a66055b70acfcc4f6c957cebf19f4504.tar.gz |
Fixed missing close of the ComboBox when clicking on it
The mouse event that dismissed a popup window should
not dispatched to the visual item. Otherwise the
menu open again.
Task-number: QTBUG-44532
Change-Id: Id8aca1634e4f1795e546230953bff49518589714
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
-rw-r--r-- | src/controls/qquickmenupopupwindow.cpp | 14 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_combobox.qml | 14 |
2 files changed, 23 insertions, 5 deletions
diff --git a/src/controls/qquickmenupopupwindow.cpp b/src/controls/qquickmenupopupwindow.cpp index 2a91940e..a578ea62 100644 --- a/src/controls/qquickmenupopupwindow.cpp +++ b/src/controls/qquickmenupopupwindow.cpp @@ -184,11 +184,15 @@ QQuickMenuBar *QQuickMenuPopupWindow::menuBar() const bool QQuickMenuPopupWindow::shouldForwardEventAfterDismiss(QMouseEvent *e) const { - // The events that dismissed a popup child of a menu contained in the menubar - // are never forwarded - if (QQuickMenuBar *mb = menuBar()) { - QPoint parentPos = transientParent()->mapFromGlobal(mapToGlobal(e->pos())); - if (!mb->isNative() && mb->contentItem()->contains(parentPos)) + // If the event falls inside this item the event should not be forwarded. + // For example for comboboxes or top menus of the menubar + QQuickMenuBar *mb = menuBar(); + QQuickItem *item = mb && !mb->isNative() ? mb->contentItem() : menu()->visualItem(); + QWindow *window = transientParent(); + if (item && window && item->window() == window) { + QPointF pos = window->mapFromGlobal(mapToGlobal(e->pos())); + pos = item->mapFromScene(pos); + if (item->contains(pos)) return false; } diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index cecc3928..7db9a75e 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -774,5 +774,19 @@ TestCase { compare(comboBox.currentText, "Pomegranate") comboBox.destroy() } + + function test_qtBug44532() { + if (Qt.platform.os === "osx") + skip("When the menu pops up on OS X, it does not return and the test fails after time out") + var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.2 ; ComboBox { model: ["A", "BB", "CCCCC"] }', container, '') + var popup = comboBox.__popup + verify(popup) + tryCompare(popup, "__popupVisible", false) + mouseClick(comboBox) + tryCompare(popup, "__popupVisible", true) + mouseClick(comboBox) + tryCompare(popup, "__popupVisible", false) + comboBox.destroy() + } } } |