summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-02-21 16:07:05 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-02-22 07:55:30 +0100
commit9ddc02024644e0c6801f71b0f9844918de288a7b (patch)
treefe046a2313f8b554b925a928bae67298ff9f1657 /tests/auto/widgets
parent87c6e340a9cd64b0cfd2c77a68bf4fec84d3dd1a (diff)
Stabilize tst_QTabBar::hoverTab()
Port the test to use the QWindow* based overloads of QTest::mouseMove() and move the cursor away. Pick-to: 6.3 Task-number: QTBUG-98489 Change-Id: Id1ac0ef176c6f9bf179f989ddd5775877525fc0d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp
index f51f0a23d5..36d264a121 100644
--- a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp
+++ b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp
@@ -36,6 +36,8 @@
#include <QStyleOptionTab>
#include <QProxyStyle>
#include <QTimer>
+#include <QScreen>
+#include <QWindow>
class TabBar;
@@ -1246,9 +1248,10 @@ void tst_QTabBar::currentTabLargeFont()
void tst_QTabBar::hoverTab_data()
{
- // Since we still rely on moving the mouse via QCursor::setPos in QTest::mouseMove,
+ // Move the cursor away from the widget as not to interfere.
// skip this test if we can't
- const QPoint cursorPos = QCursor::pos() + QPoint(10, 10);
+ const QPoint topLeft = QGuiApplication::primaryScreen()->availableGeometry().topLeft();
+ const QPoint cursorPos = topLeft + QPoint(10, 10);
QCursor::setPos(cursorPos);
if (!QTest::qWaitFor([cursorPos]{ return QCursor::pos() == cursorPos; }, 500))
QSKIP("Can't move mouse");
@@ -1261,7 +1264,7 @@ void tst_QTabBar::hoverTab_data()
void tst_QTabBar::hoverTab()
{
QFETCH(bool, documentMode);
- QWidget window;
+ QWidget topLevel;
class TabBar : public QTabBar
{
public:
@@ -1272,7 +1275,7 @@ void tst_QTabBar::hoverTab()
styleOptions[tabIndex] = *option;
}
mutable QHash<int, QStyleOptionTab> styleOptions;
- } tabbar(&window);
+ } tabbar(&topLevel);
tabbar.setDocumentMode(documentMode);
tabbar.addTab("A");
@@ -1281,7 +1284,10 @@ void tst_QTabBar::hoverTab()
tabbar.addTab("D");
tabbar.move(0,0);
- window.setMinimumSize(tabbar.sizeHint());
+ const QSize size = tabbar.sizeHint();
+ const auto center = topLevel.screen()->availableGeometry().center();
+ topLevel.move(center - QPoint{size.width(), size.height()} / 2);
+ topLevel.setMinimumSize(size);
tabbar.ensurePolished();
// some styles set those flags, some don't. If not, use a style sheet
@@ -1293,21 +1299,25 @@ void tst_QTabBar::hoverTab()
)");
}
- window.show();
- QVERIFY(QTest::qWaitForWindowExposed(&window));
+ topLevel.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
+ auto *window = topLevel.windowHandle();
- QTest::mouseMove(&tabbar, tabbar.tabRect(0).center());
+ auto pos = tabbar.mapToParent(tabbar.tabRect(0).center());
+ QTest::mouseMove(window, pos);
QTRY_VERIFY(tabbar.styleOptions[0].state & QStyle::State_Selected);
QTRY_COMPARE(tabbar.styleOptions[1].state & QStyle::State_MouseOver, QStyle::State_None);
QTRY_COMPARE(tabbar.styleOptions[2].state & QStyle::State_MouseOver, QStyle::State_None);
QTRY_COMPARE(tabbar.styleOptions[3].state & QStyle::State_MouseOver, QStyle::State_None);
- QTest::mouseMove(&tabbar, tabbar.tabRect(1).center());
+ pos = tabbar.mapToParent(tabbar.tabRect(1).center());
+ QTest::mouseMove(window, pos);
QTRY_COMPARE(tabbar.styleOptions[1].state & QStyle::State_MouseOver, QStyle::State_MouseOver);
QCOMPARE(tabbar.styleOptions[2].state & QStyle::State_MouseOver, QStyle::State_None);
QCOMPARE(tabbar.styleOptions[3].state & QStyle::State_MouseOver, QStyle::State_None);
- QTest::mouseMove(&tabbar, tabbar.tabRect(2).center());
+ pos = tabbar.mapToParent(tabbar.tabRect(2).center());
+ QTest::mouseMove(window, pos);
QTRY_COMPARE(tabbar.styleOptions[2].state & QStyle::State_MouseOver, QStyle::State_MouseOver);
QCOMPARE(tabbar.styleOptions[1].state & QStyle::State_MouseOver, QStyle::State_None);
QCOMPARE(tabbar.styleOptions[3].state & QStyle::State_MouseOver, QStyle::State_None);