Skip to content

Commit ceace5f

Browse files
author
Santhosh Kumar
committed
Reset hover state for the items within the quick popup window
The hovered state of the item within the quick popup has not been reset when another modal popup is placed over it. This is because, after patch 48da34f, the overlay filters the hover events of the quick controls which are modally blocked. But this can create an issue if the child item of the pop is already in a hovered state and there is another modal popup placed over it, as any further hover events (including the HoverLeave of the control item) will be forwarded and handled by the modal popup which doesn't allow the child item to resets its hovered state. This patch allows the child item of the popup to handle hover release event when it's already in the hovered state. Fixes: QTBUG-126626 Pick-to: 6.5 6.2 Change-Id: Ibf7f5ad8653a8c0df9968114ab6b8228acba9d6e Reviewed-by: Shawn Rutledge <[email protected]> (cherry picked from commit 7712fbc) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit 6958577) Reviewed-by: Fabian Kosmale <[email protected]>
1 parent 4e08af2 commit ceace5f

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

src/quicktemplates/qquickoverlay.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,13 @@ bool QQuickOverlay::childMouseEventFilter(QQuickItem *item, QEvent *event)
456456
case QEvent::HoverEnter:
457457
case QEvent::HoverMove:
458458
case QEvent::HoverLeave:
459+
// If the control item has already been hovered, allow the hover leave event
460+
// to be processed by the same item for resetting its internal hovered state
461+
// instead of filtering it here.
462+
if (auto *control = qobject_cast<QQuickControl *>(item)) {
463+
if (control->isHovered() && event->type() == QEvent::HoverLeave)
464+
return false;
465+
}
459466
handled = d->handleHoverEvent(item, static_cast<QHoverEvent *>(event), popup);
460467
break;
461468

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import QtQuick
2+
import QtQuick.Controls
3+
4+
ApplicationWindow {
5+
id: root
6+
width: 100
7+
height: 100
8+
property alias controlsPopup: _controlsPopup
9+
property alias blockInputPopup: _blockInputPopup
10+
Popup {
11+
id: _controlsPopup
12+
width: parent.width
13+
height: parent.height
14+
modal: true
15+
Control {
16+
id: controls
17+
anchors.fill: parent
18+
hoverEnabled: true
19+
contentItem: Text { text: "Test Control" }
20+
}
21+
}
22+
Popup {
23+
id: _blockInputPopup
24+
width: parent.width
25+
height: parent.height
26+
modal: true
27+
}
28+
}

tests/auto/quickcontrols/qquickpopup/tst_qquickpopup.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ private slots:
106106
void fadeDimmer_data();
107107
void fadeDimmer();
108108
void noDimmer();
109+
void resetHoveredStateForItemsWithinPopup();
109110

110111
private:
111112
QScopedPointer<QPointingDevice> touchScreen = QScopedPointer<QPointingDevice>(QTest::createTouchDevice());
@@ -2358,6 +2359,39 @@ void tst_QQuickPopup::noDimmer()
23582359
QTRY_VERIFY(!drawer->isModal());
23592360
}
23602361

2362+
void tst_QQuickPopup::resetHoveredStateForItemsWithinPopup()
2363+
{
2364+
QQuickControlsApplicationHelper helper(this, "resetHoveredForItemsWithinOverlay.qml");
2365+
QVERIFY2(helper.ready, helper.failureMessage());
2366+
2367+
QQuickWindow *window = helper.window;
2368+
window->show();
2369+
QVERIFY(QTest::qWaitForWindowExposed(window));
2370+
2371+
QQuickPopup *controlsPopup = window->property("controlsPopup").value<QQuickPopup*>();
2372+
QVERIFY(controlsPopup);
2373+
2374+
QQuickPopup *blockInputPopup = window->property("blockInputPopup").value<QQuickPopup*>();
2375+
QVERIFY(controlsPopup);
2376+
2377+
controlsPopup->open();
2378+
QTRY_VERIFY(controlsPopup->isOpened());
2379+
2380+
QTest::mouseMove(window, QPoint(window->width() / 2, window->height() / 2));
2381+
2382+
auto *controlItem = qobject_cast<QQuickControl *>(controlsPopup->contentItem()->childItems().at(0));
2383+
QVERIFY(controlItem);
2384+
// Check hover enabled for the control item within the popup
2385+
QTRY_VERIFY(controlItem->isHovered());
2386+
2387+
// Open the modal popup window over the existing control item
2388+
blockInputPopup->open();
2389+
QTRY_VERIFY(blockInputPopup->isOpened());
2390+
2391+
// Control item hovered shall be disabled once we open the modal popup
2392+
QTRY_VERIFY(!controlItem->isHovered());
2393+
}
2394+
23612395
QTEST_QUICKCONTROLS_MAIN(tst_QQuickPopup)
23622396

23632397
#include "tst_qquickpopup.moc"

0 commit comments

Comments
 (0)