Skip to content

Commit

Permalink
DA: don't exit early from deliverHoverEvents when we have hovered items
Browse files Browse the repository at this point in the history
The current implementation would exit early if subtreeHoverEnabled
was false. The problem is that this can also happen if you set
hoverEnabled to false while an item is being hovered. And in that
case, we need to prune the list of hovered items.

This patch will therefore ensure that we only exit early if
subtreeHoverEnabled is false, _and_ no items are currently
marked as being hovered.

Pick-to: 6.4 6.2
Change-Id: I6086c7cbea07b0973db343a3f439810361c5d1b7
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
  • Loading branch information
Richard Moe Gustavsen committed Sep 20, 2022
1 parent ec5e768 commit 255c041
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/quick/util/qquickdeliveryagent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -967,9 +967,6 @@ bool QQuickDeliveryAgentPrivate::deliverHoverEvent(
const QPointF &scenePos, const QPointF &lastScenePos,
Qt::KeyboardModifiers modifiers, ulong timestamp)
{
if (!QQuickItemPrivate::get(rootItem)->subtreeHoverEnabled)
return false;

// The first time this function is called, hoverItems is empty.
// We then call deliverHoverEventRecursive from the rootItem, and
// populate the list with all the children and grandchildren that
Expand All @@ -985,11 +982,19 @@ bool QQuickDeliveryAgentPrivate::deliverHoverEvent(
// visit will still have an old hoverId. We can therefore go through the
// list at the end of this function and look for items with an old hoverId,
// remove them from the list, and update their state accordingly.
currentHoverId++;
hoveredLeafItemFound = false;

const bool subtreeHoverEnabled = QQuickItemPrivate::get(rootItem)->subtreeHoverEnabled;
const bool itemsWasHovered = !hoverItems.isEmpty();
deliverHoverEventRecursive(rootItem, scenePos, lastScenePos, modifiers, timestamp);

if (!subtreeHoverEnabled && !itemsWasHovered)
return false;

currentHoverId++;

if (subtreeHoverEnabled) {
hoveredLeafItemFound = false;
deliverHoverEventRecursive(rootItem, scenePos, lastScenePos, modifiers, timestamp);
}

// Prune the list for items that are no longer hovered
for (auto it = hoverItems.begin(); it != hoverItems.end();) {
Expand Down

0 comments on commit 255c041

Please sign in to comment.