summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2021-05-12 11:21:07 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2021-05-12 20:50:02 +0200
commit3224c6d7d150164241c13ccf7d47377a39c0a6bb (patch)
tree592cde2fdf9ba6d2ddc3bce70d1c9a5551e806c3 /src
parent776a969bfd426a697ce95481ab7989f9bb351552 (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). Pick-to: 6.1 5.15 Fixes: QTBUG-70137 Change-Id: Ic309ee8f419b9c14894255205867bce11dc0c414 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/widgets/qdockwidget.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp
index 548078098c..5016235755 100644
--- a/src/widgets/widgets/qdockwidget.cpp
+++ b/src/widgets/widgets/qdockwidget.cpp
@@ -970,13 +970,27 @@ bool QDockWidgetPrivate::mouseMoveEvent(QMouseEvent *event)
&& mwlayout->pluggingWidget == nullptr
&& (event->position().toPoint() - 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->globalPosition().toPoint() - state->pressPos - windowMarginOffset;