diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index 30d5e4400d..0da36f9262 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -350,11 +350,23 @@ public: QWidget *native, QWidget **buttonDown, QPointer &lastMouseReceiver, bool spontaneous = true); void sendSyntheticEnterLeave(QWidget *widget); -#ifdef Q_OS_WIN - static HWND getHWNDForWidget(QWidget *widget) + + static QWindow *windowForWidget(const QWidget *widget) { - QWindow *window = widget->windowHandle(); - return static_cast (QGuiApplication::platformNativeInterface()->nativeResourceForWindow("handle", window)); + if (QWindow *window = widget->windowHandle()) + return window; + if (const QWidget *nativeParent = widget->nativeParentWidget()) + return nativeParent->windowHandle(); + return 0; + } + +#ifdef Q_OS_WIN + static HWND getHWNDForWidget(const QWidget *widget) + { + if (QWindow *window = windowForWidget(widget)) + return static_cast (QGuiApplication::platformNativeInterface()-> + nativeResourceForWindow(QByteArrayLiteral("handle"), window)); + return 0; } #endif