diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2021-05-12 11:21:07 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-05-24 17:40:03 +0000 |
commit | 3d5d5cbe71d9f556aac888353efe7c2b9b219b52 (patch) | |
tree | 5b322be9c75b59a78d5a2288aa0b1e348021d84f /src | |
parent | 0a1ac231f8ea33c5d3467fe5107255475ce606ce (diff) |
QDockWidget, macOS: don't drag on native widgets
When using native dock widgets on macOS, it will currently
fail if you try to drag on a dock widget inside QMainWindow
to make it floating. The reason is that the drag will
basically start as as drag inside one NSWindow (QMainWindow),
but continue as a drag on another NSWindow (QDockWidget).
And this is not handled well by AppKit, especially since the
NSView where the drag was started is reparented into a new
NSWindow (the floating QDockWidget) while the dragging is
ongoing. And there seems to be no practical solution to how
we can support this from the cocoa QPA plugin
This patch will therefore change the logic in QDockWidget to
simply make the dock widget floating if you drag on it, rather
than actually starting a drag (but only for the described case).
Fixes: QTBUG-70137
Change-Id: Ic309ee8f419b9c14894255205867bce11dc0c414
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 3224c6d7d150164241c13ccf7d47377a39c0a6bb)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/widgets/qdockwidget.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp index f295b62ff3..0feb3222f3 100644 --- a/src/widgets/widgets/qdockwidget.cpp +++ b/src/widgets/widgets/qdockwidget.cpp @@ -973,13 +973,27 @@ bool QDockWidgetPrivate::mouseMoveEvent(QMouseEvent *event) && mwlayout->pluggingWidget == nullptr && (event->pos() - state->pressPos).manhattanLength() > QApplication::startDragDistance()) { - startDrag(); - q->grabMouse(); - ret = true; + +#ifdef Q_OS_MACOS + if (windowHandle()) { + // When using native widgets on mac, we have not yet been successful in + // starting a drag on an NSView that belongs to one window (QMainWindow), + // but continue the drag on another (QDockWidget). This is what happens if + // we try to make this widget floating during a drag. So as a fall back + // solution, we simply make this widget floating instead, when we would + // otherwise start a drag. + q->setFloating(true); + } else +#endif + { + startDrag(); + q->grabMouse(); + ret = true; + } } } - if (state->dragging && !state->nca) { + if (state && state->dragging && !state->nca) { QMargins windowMargins = q->window()->windowHandle()->frameMargins(); QPoint windowMarginOffset = QPoint(windowMargins.left(), windowMargins.top()); QPoint pos = event->globalPos() - state->pressPos - windowMarginOffset; |