diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-09-03 15:46:37 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-09-05 15:59:28 +0000 |
commit | df12dbe976876bbb4e36b16eb4836c4109bb80d0 (patch) | |
tree | 0cdba412955244ee7ae9d95a95c08e88cea8ee9b /src | |
parent | 14dd934c3203b614e43be9fa5b17761d43092351 (diff) |
Fix hover event delivery with plain QQuickWindow
A plain QQuickWindow cannot provide a modal background dimming visual,
but we can create a QQuickItem as a fallback to take care of blocking
the hover events for modal popups.
Change-Id: I3ead985c4e2e030aaf28f1ec6c8a1ae285637819
Task-number: QTBUG-54913
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quicktemplates2/qquickoverlay.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/quicktemplates2/qquickoverlay.cpp b/src/quicktemplates2/qquickoverlay.cpp index 0395ed41..7e9e57f4 100644 --- a/src/quicktemplates2/qquickoverlay.cpp +++ b/src/quicktemplates2/qquickoverlay.cpp @@ -101,15 +101,21 @@ void QQuickOverlayPrivate::popupAboutToHide() static QQuickItem *createDimmer(QQmlComponent *component, QQuickPopup *popup, QQuickItem *parent) { - if (!component) - return nullptr; + QQuickItem *item = nullptr; + if (component) { + QQmlContext *creationContext = component->creationContext(); + if (!creationContext) + creationContext = qmlContext(parent); + QQmlContext *context = new QQmlContext(creationContext); + context->setContextObject(popup); + item = qobject_cast<QQuickItem*>(component->beginCreate(context)); + } + + // when there is no overlay component available (with plain QQuickWindow), + // use a plain QQuickItem as a fallback to block hover events + if (!item && popup->isModal()) + item = new QQuickItem; - QQmlContext *creationContext = component->creationContext(); - if (!creationContext) - creationContext = qmlContext(parent); - QQmlContext *context = new QQmlContext(creationContext); - context->setContextObject(popup); - QQuickItem *item = qobject_cast<QQuickItem*>(component->beginCreate(context)); if (item) { item->setOpacity(popup->isVisible() ? 1.0 : 0.0); item->setParentItem(parent); @@ -121,7 +127,8 @@ static QQuickItem *createDimmer(QQmlComponent *component, QQuickPopup *popup, QQ // item->setAcceptHoverEvents(QGuiApplication::styleHints()->useHoverEffects()); // connect(QGuiApplication::styleHints(), &QStyleHints::useHoverEffectsChanged, item, &QQuickItem::setAcceptHoverEvents); } - component->completeCreate(); + if (component) + component->completeCreate(); } return item; } |