QQuickMouseArea: fix containsMouse when mousearea become visible

If enabled is false, then containsMouse will not become true when
hovering on mousearea, even if hoverEnabled is true. However when an
invisible mousearea become visible, the value of enabled isn't
checked. In this case, the value of containsMouse is not affected by
enabled.

[ChangeLog][QtQuick][QQuickMouseArea] containsMouse property will
not become true when the an invisible mousearea become visible, if
the enabled property is false or its parent item is not enabled

Fixes: QTBUG-77983
Change-Id: I923bdcf3eda813aea51a04515d530093d6eb77b2
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Wang Chuan 2019-09-19 18:04:55 +08:00
parent e2df4233a7
commit 8f1857f907
2 changed files with 29 additions and 1 deletions

View File

@ -1069,7 +1069,7 @@ void QQuickMouseArea::itemChange(ItemChange change, const ItemChangeData &value)
Q_D(QQuickMouseArea);
switch (change) {
case ItemVisibleHasChanged:
if (acceptHoverEvents() && d->hovered != (isVisible() && isUnderMouse())) {
if (d->effectiveEnable && d->enabled && acceptHoverEvents() && d->hovered != (isVisible() && isUnderMouse())) {
if (!d->hovered) {
QPointF cursorPos = QGuiApplicationPrivate::lastCursorPosition;
d->lastScenePos = d->window->mapFromGlobal(cursorPos.toPoint());

View File

@ -1359,6 +1359,34 @@ void tst_QQuickMouseArea::hoverVisible()
QCOMPARE(enteredSpy.count(), 1);
QCOMPARE(QPointF(mouseTracker->mouseX(), mouseTracker->mouseY()), QPointF(11,33));
// QTBUG-77983
mouseTracker->setVisible(false);
mouseTracker->setEnabled(false);
QCOMPARE(mouseTracker->hovered(), false);
mouseTracker->setVisible(true);
// if the enabled property is false, the containsMouse property shouldn't become true
// when an invisible mousearea become visible
QCOMPARE(mouseTracker->hovered(), false);
mouseTracker->parentItem()->setEnabled(false);
mouseTracker->setVisible(false);
mouseTracker->setEnabled(true);
QCOMPARE(mouseTracker->hovered(), false);
mouseTracker->setVisible(true);
// if the parent item is not enabled, the containsMouse property will be false, even if
// the mousearea is enabled
QCOMPARE(mouseTracker->hovered(), false);
mouseTracker->parentItem()->setEnabled(true);
mouseTracker->setVisible(false);
mouseTracker->setEnabled(true);
QCOMPARE(mouseTracker->hovered(), false);
mouseTracker->setVisible(true);
QCOMPARE(mouseTracker->hovered(), true);
}
void tst_QQuickMouseArea::hoverAfterPress()