diff options
author | Paul Olav Tvete <paul.tvete@qt.io> | 2019-12-02 17:30:18 +0100 |
---|---|---|
committer | Paul Olav Tvete <paul.tvete@qt.io> | 2019-12-05 10:05:04 +0100 |
commit | 5a6fb46488ebc26b79b9d37a7f91969e0d852b4f (patch) | |
tree | 3115d9679ef946d004a2ce9f57f9c877181a5643 | |
parent | 913146ccd401216f71f037ea304b5e61b7a138cf (diff) |
QGraphicsItem: Fix mouse tracking with modal panels
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 <volker.hilsheimer@qt.io>
Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
-rw-r--r-- | src/widgets/graphicsview/qgraphicsscene.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index a47d0d879d..d641d17232 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -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(); } |