diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index 06680228bc2a61fee6454d84aad9458e1d11f53f..6234c0dcbe75288968628672f17a89b79c709e1c 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -686,7 +686,23 @@ static NSString *_q_NSWindowDidChangeOcclusionStateNotification = nil;
             m_platformWindow->m_forwardWindow = 0;
     }
 
-    [targetView convertFromScreen:[NSEvent mouseLocation] toWindowPoint:&qtWindowPoint andScreenPoint:&qtScreenPoint];
+    NSPoint globalPos = [NSEvent mouseLocation];
+
+    if ([self.window parentWindow]
+        && (theEvent.type == NSLeftMouseDragged || theEvent.type == NSLeftMouseUp)) {
+        // QToolBar can be implemented as a child window on top of its main window
+        // (with a borderless NSWindow). If an option "unified toolbar" set on the main window,
+        // it's possible to drag such a window using this toolbar.
+        // While handling mouse drag events, QToolBar moves the window (QWidget::move).
+        // In such a combination [NSEvent mouseLocation] is very different from the
+        // real event location and as a result a window will move chaotically.
+        NSPoint winPoint = [theEvent locationInWindow];
+        NSRect tmpRect = NSMakeRect(winPoint.x, winPoint.y, 1., 1.);
+        tmpRect = [[theEvent window] convertRectToScreen:tmpRect];
+        globalPos = tmpRect.origin;
+    }
+
+    [targetView convertFromScreen:globalPos toWindowPoint:&qtWindowPoint andScreenPoint:&qtScreenPoint];
     ulong timestamp = [theEvent timestamp] * 1000;
 
     QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();