diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
index 3b4ae73febcbc8067bfdec650eaed1e58907e995..ff29f998754e4be69568e54af2bdc2c7038ed212 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
@@ -3492,6 +3492,8 @@ void tst_QGraphicsScene::task160653_selectionChanged()
 
     QSignalSpy spy(&scene, SIGNAL(selectionChanged()));
     QGraphicsView view(&scene);
+    view.show();
+    QVERIFY(QTest::qWaitForWindowActive(&view));
     QTest::mouseClick(
         view.viewport(), Qt::LeftButton, 0, view.mapFromScene(scene.items().first()->scenePos()));
     QCOMPARE(spy.count(), 1);
diff --git a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp
index 9b92c34fb5351437afc240b2ae380a609d39750f..ec2203e615c4146962fb9b954c30302c87049f77 100644
--- a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp
@@ -182,14 +182,6 @@ private slots:
     void QTBUG_45867_send_itemChildAddedChange_to_parent();
 };
 
-
-static void sendMouseMove(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons buttons = 0)
-{
-    QTest::mouseMove(widget, point);
-    QMouseEvent event(QEvent::MouseMove, point, button, buttons, 0);
-    QApplication::sendEvent(widget, &event);
-}
-
 // Subclass that exposes the protected functions.
 class SubQGraphicsWidget : public QGraphicsWidget {
 public:
@@ -197,7 +189,7 @@ public:
         : QGraphicsWidget(parent, windowFlags), eventCount(0)
         { }
 
-    void initStyleOption(QStyleOption *option)
+    void initStyleOption(QStyleOption *option) const
         { QGraphicsWidget::initStyleOption(option); }
 
     void call_changeEvent(QEvent* event)
@@ -1110,8 +1102,8 @@ void tst_QGraphicsWidget::initStyleOption()
 {
     QGraphicsScene scene;
     QGraphicsView view(&scene);
+    view.resize(300, 300);
     view.show();
-    QApplication::setActiveWindow(&view);
     QVERIFY(QTest::qWaitForWindowActive(&view));
 
     view.setAlignment(Qt::AlignTop | Qt::AlignLeft);
@@ -1133,10 +1125,8 @@ void tst_QGraphicsWidget::initStyleOption()
     }
     QFETCH(bool, underMouse);
     if (underMouse) {
-        view.resize(300, 300);
-        view.show();
-        QVERIFY(QTest::qWaitForWindowActive(&view));
-        sendMouseMove(view.viewport(), view.mapFromScene(widget->mapToScene(widget->boundingRect().center())));
+        QCursor::setPos(view.viewport()->mapToGlobal(view.mapFromScene(widget->mapToScene(widget->boundingRect().center()))));
+        QTest::qWait(100);
     }
 
     QFETCH(QPalette, palette);