From 0ab701bab64a92e68437a3010b51ed116eebb3ff Mon Sep 17 00:00:00 2001 From: Eism Date: Mon, 24 May 2021 11:41:43 +0100 Subject: [PATCH] qtquick: Fix detecting top level geometry For QtQuick we want the QWindow geometry. For QtWidget it just works, as the top level widget as the same geometry as the window, unlike QQuickItem. Fixes issue #199 --- src/private/DragController.cpp | 13 ++++++++++++- tests/tst_docks.cpp | 4 ---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/private/DragController.cpp b/src/private/DragController.cpp index 665b8367..8347a8bb 100644 --- a/src/private/DragController.cpp +++ b/src/private/DragController.cpp @@ -787,6 +787,15 @@ static QWidgetOrQuick *qtTopLevelForHWND(HWND hwnd) return nullptr; } #endif + +static QRect topLevelGeometry(const QWidgetOrQuick* topLevel) +{ + if (auto mainWindow = qobject_cast(topLevel)) + return mainWindow->windowGeometry(); + + return topLevel->geometry(); +} + template static WidgetType* qtTopLevelUnderCursor_impl(QPoint globalPos, const QVector &windows, T windowBeingDragged) { @@ -832,7 +841,9 @@ WidgetType *DragController::qtTopLevelUnderCursor() const continue; if (auto tl = qtTopLevelForHWND(hwnd)) { - if (tl->geometry().contains(globalPos) && tl->objectName() != QStringLiteral("_docks_IndicatorWindow_Overlay")) { + const QRect windowGeometry = topLevelGeometry(tl); + + if (windowGeometry.contains(globalPos) && tl->objectName() != QStringLiteral("_docks_IndicatorWindow_Overlay")) { qCDebug(toplevels) << Q_FUNC_INFO << "Found top-level" << tl; return tl; } diff --git a/tests/tst_docks.cpp b/tests/tst_docks.cpp index ddca6a2a..8689e962 100644 --- a/tests/tst_docks.cpp +++ b/tests/tst_docks.cpp @@ -933,10 +933,6 @@ void TestDocks::tst_hoverShowsDropIndicators() auto fw = floatingDockWidget->floatingWindow(); dragFloatingWindowTo(fw, mainWindowCenterPos); -#if defined(Q_OS_WIN32) - if (!isOffscreen()) - QEXPECT_FAIL("", "to be fixed", Continue); -#endif QCOMPARE(dock0->dptr()->frame()->dockWidgetCount(), 2); } #endif