diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 83678ddf678079c92e7a2e9c766c049d8fb2ff2c..94904c12f63884e61e121520ec0a5e39206221b7 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -320,6 +320,7 @@ void QCocoaWindow::setVisible(bool visible)
         // - QNSViews for child windows are initialy not hidden and won't get the
         //   viewDidUnhide message.
         exposeWindow();
+        QWindowSystemInterface::flushWindowSystemEvents();
 
         if (m_nsWindow) {
             // setWindowState might have been called while the window was hidden and
diff --git a/tests/auto/opengl/qgl/tst_qgl.cpp b/tests/auto/opengl/qgl/tst_qgl.cpp
index 00973cf533d5e045e6b66e4f4d7dc0c164ba8e5b..28ec699427c0085014d62dcc551cc5d869fe2a7c 100644
--- a/tests/auto/opengl/qgl/tst_qgl.cpp
+++ b/tests/auto/opengl/qgl/tst_qgl.cpp
@@ -875,6 +875,10 @@ void tst_QGL::graphicsViewClipping()
     scene.setSceneRect(view.viewport()->rect());
 
     QVERIFY(QTest::qWaitForWindowExposed(&view));
+    #ifdef Q_OS_MAC
+        // The black rectangle jumps from the center to the upper left for some reason.
+        QTest::qWait(100);
+    #endif
 
     QTRY_VERIFY(widget->painted);