diff options
-rw-r--r-- | src/widgets/widgets/qtabbar.cpp | 6 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp | 38 |
2 files changed, 42 insertions, 2 deletions
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index a3b926e549..a3914dccfe 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -2304,6 +2304,8 @@ void QTabBar::mouseReleaseEvent(QMouseEvent *event) d->dragStartPosition = QPoint(); } + // mouse release event might happen outside the tab, so keep the pressed index + int oldPressedIndex = d->pressedIndex; int i = d->indexAtPos(event->position().toPoint()) == d->pressedIndex ? d->pressedIndex : -1; d->pressedIndex = -1; QStyleOptionTabBarBase optTabBase; @@ -2313,8 +2315,8 @@ void QTabBar::mouseReleaseEvent(QMouseEvent *event) (style()->styleHint(QStyle::SH_TabBar_SelectMouseType, &optTabBase, this) == QEvent::MouseButtonRelease); if (selectOnRelease) setCurrentIndex(i); - if (!selectOnRelease || !d->validIndex(i) || d->currentIndex == i) - repaint(tabRect(i)); + if (d->validIndex(oldPressedIndex)) + update(tabRect(oldPressedIndex)); } /*!\reimp 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" |