Skip to content

Commit

Permalink
QGraphicsItem: Fix mouse tracking with modal panels
Browse files Browse the repository at this point in the history
This fixes the case where a mouse tracking item is added to the
scene while a modal panel is blocking. In order to optimize event
delivery, mouse tracking is enabled for the view only when an
item that needs it is added. This means that we cannot use
itemAcceptsHoverEvents_helper(), since that returns whether the
item _currently_ needs hover events, and we need to know whether it
will need them in the future.

[ChangeLog][QtWidgets][QGraphicsView] Fixed a bug where hover events
would not be delivered if the item was added while blocked by a modal panel.

Fixes: QTBUG-77233
Change-Id: Ifc95869f2cc9c8c048330928ef8a13cd27cfd0f9
Reviewed-by: Volker Hilsheimer <[email protected]>
Reviewed-by: Andreas Aardal Hanssen <[email protected]>
  • Loading branch information
paulolav committed Dec 5, 2019
1 parent 913146c commit 5a6fb46
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/widgets/graphicsview/qgraphicsscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2568,8 +2568,16 @@ void QGraphicsScene::addItem(QGraphicsItem *item)
++d->selectionChanging;
int oldSelectedItemSize = d->selectedItems.size();

// Enable mouse tracking if the item accepts hover events or has a cursor set.
if (d->allItemsIgnoreHoverEvents && d->itemAcceptsHoverEvents_helper(item)) {
// Enable mouse tracking if we haven't already done so, and the item needs it.
// We cannot use itemAcceptsHoverEvents_helper() here, since we need to enable
// mouse tracking also if this item is temporarily blocked by a modal panel.

auto needsMouseTracking = [](const QGraphicsItemPrivate *item) {
return item->acceptsHover
|| (item->isWidget && static_cast<const QGraphicsWidgetPrivate *>(item)->hasDecoration());
};

if (d->allItemsIgnoreHoverEvents && needsMouseTracking(item->d_ptr.data())) {
d->allItemsIgnoreHoverEvents = false;
d->enableMouseTrackingOnViews();
}
Expand Down

0 comments on commit 5a6fb46

Please sign in to comment.