summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorWang Chuan <ouchuanm@outlook.com>2020-06-26 23:43:26 +0800
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-07-02 04:17:52 +0200
commitc513b1214e38829e9bc23bb2ef948f5c388071a7 (patch)
treea03bbb9419559308153b16bd85deefb3f73f6d50 /tests/auto
parent843b40328610c5e61bd7cada03c2046ece788b02 (diff)
QTabBar: make sure the tab is repainted after releasing mouse
The tab has to be repainted even f the mouse release event happened outside the tab bar, otherwise it will look like the tab is still pressed. As a drive-by, replace the repaint() call with update(); there is no need for synchronous painting in an event handler. Pick-to: 5.15 Fixes: QTBUG-81637 Change-Id: Ia55182be906511ac3b462f00add8a621c6c05fc3 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp
index 444a341a70..1cb6c6831f 100644
--- a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp
+++ b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp
@@ -92,6 +92,8 @@ private slots:
void tabBarClicked();
void autoHide();
+
+ void mouseReleaseOutsideTabBar();
};
// Testing get/set functions
@@ -796,5 +798,41 @@ void tst_QTabBar::autoHide()
QVERIFY(tabBar.isVisible());
}
+void tst_QTabBar::mouseReleaseOutsideTabBar()
+{
+ class RepaintChecker : public QObject
+ {
+ public:
+ bool repainted = false;
+ QRect rectToBeRepainted;
+ bool eventFilter(QObject *, QEvent *event) override
+ {
+ if (event->type() == QEvent::Paint
+ && rectToBeRepainted.contains(static_cast<QPaintEvent *>(event)->rect()))
+ repainted = true;
+ return false;
+ }
+ } repaintChecker;
+
+ QTabBar tabBar;
+ tabBar.installEventFilter(&repaintChecker);
+ tabBar.addTab(" ");
+ tabBar.addTab(" ");
+ tabBar.show();
+ if (!QTest::qWaitForWindowExposed(&tabBar))
+ QSKIP("Window failed to show, skipping test");
+
+ QRect tabRect = tabBar.tabRect(1);
+ QPoint tabCenter = tabRect.center();
+ QTest::mousePress(&tabBar, Qt::LeftButton, {}, tabCenter);
+ QTest::mouseEvent(QTest::MouseMove, &tabBar, Qt::LeftButton, {}, tabCenter + QPoint(tabCenter.x(), tabCenter.y() + tabRect.height()));
+
+ // make sure the holding tab is repainted after releasing the mouse
+ repaintChecker.repainted = false;
+ repaintChecker.rectToBeRepainted = tabRect;
+ QTest::mouseRelease(&tabBar, Qt::LeftButton, {}, tabCenter + QPoint(tabCenter.x(), tabCenter.y() + tabRect.height()));
+ QTRY_VERIFY(repaintChecker.repainted);
+}
+
QTEST_MAIN(tst_QTabBar)
#include "tst_qtabbar.moc"