diff --git a/src/widgets/widgetwindowagent.cpp b/src/widgets/widgetwindowagent.cpp index 0ae4fed..82ee46d 100644 --- a/src/widgets/widgetwindowagent.cpp +++ b/src/widgets/widgetwindowagent.cpp @@ -8,11 +8,34 @@ #include #include #include +#include #include "widgetitemdelegate_p.h" namespace QWK { +#if defined(Q_OS_WINDOWS) && !QWINDOWKIT_CONFIG(FORCE_QT_WINDOW_CONTEXT) + namespace { + class WindowBoundWidgetItemDelegate final : public WidgetItemDelegate { + public: + explicit WindowBoundWidgetItemDelegate(QWidget *host) : m_host(host) { + } + + QRect mapGeometryToScene(const QObject *obj) const override { + const auto *widget = static_cast(obj); + const auto *window = widget->window(); + if (!m_host || window != m_host->window()) { + return {}; + } + return {widget->mapTo(window, QPoint(0, 0)), widget->size()}; + } + + private: + QPointer m_host; + }; + } +#endif + /*! \class WidgetWindowAgent \brief WindowAgentBase is the window agent for QtWidgets. @@ -70,7 +93,11 @@ namespace QWK { // various hooks. // w->setAttribute(Qt::WA_NativeWindow); // ### FIXME: Check +#if defined(Q_OS_WINDOWS) && !QWINDOWKIT_CONFIG(FORCE_QT_WINDOW_CONTEXT) + d->setup(w, new WindowBoundWidgetItemDelegate(w)); +#else d->setup(w, new WidgetItemDelegate()); +#endif d->hostWidget = w; #ifdef Q_OS_MAC