diff options
-rw-r--r-- | src/gui/widgets/qtabbar.cpp | 15 | ||||
-rw-r--r-- | src/gui/widgets/qtabbar_p.h | 2 | ||||
-rw-r--r-- | tests/auto/qtabbar/tst_qtabbar.cpp | 35 |
3 files changed, 41 insertions, 11 deletions
diff --git a/src/gui/widgets/qtabbar.cpp b/src/gui/widgets/qtabbar.cpp index 7559311..d03a2f4 100644 --- a/src/gui/widgets/qtabbar.cpp +++ b/src/gui/widgets/qtabbar.cpp @@ -580,16 +580,10 @@ void QTabBarPrivate::layoutTab(int index) } } -void QTabBarPrivate::layoutWidgets(int index) +void QTabBarPrivate::layoutWidgets(int start) { Q_Q(QTabBar); - int start = 0; - int end = q->count(); - if (index != -1) { - start = qMax(index, 0); - end = qMin(end, start + 1); - } - for (int i = start; i < end; ++i) { + for (int i = start; i < q->count(); ++i) { layoutTab(i); } } @@ -1171,8 +1165,9 @@ void QTabBar::setCurrentIndex(int index) update(); d->makeVisible(index); d->tabList[index].lastTab = oldIndex; - d->layoutWidgets(oldIndex); - d->layoutWidgets(index); + if (oldIndex >= 0 && oldIndex < count()) + d->layoutTab(oldIndex); + d->layoutTab(index); #ifdef QT3_SUPPORT emit selected(index); #endif diff --git a/src/gui/widgets/qtabbar_p.h b/src/gui/widgets/qtabbar_p.h index 83636e6..37741f7 100644 --- a/src/gui/widgets/qtabbar_p.h +++ b/src/gui/widgets/qtabbar_p.h @@ -178,7 +178,7 @@ public: void refresh(); void layoutTabs(); - void layoutWidgets(int index = -1); + void layoutWidgets(int start = 0); void layoutTab(int index); void updateMacBorderMetrics(); void setupMovableTab(); diff --git a/tests/auto/qtabbar/tst_qtabbar.cpp b/tests/auto/qtabbar/tst_qtabbar.cpp index 72f9dd3..ac3de20 100644 --- a/tests/auto/qtabbar/tst_qtabbar.cpp +++ b/tests/auto/qtabbar/tst_qtabbar.cpp @@ -95,6 +95,8 @@ private slots: void task251184_removeTab(); void changeTitleWhileDoubleClickingTab(); + + void taskQTBUG_10052_widgetLayoutWhenMoving(); }; // Testing get/set functions @@ -576,5 +578,38 @@ void tst_QTabBar::changeTitleWhileDoubleClickingTab() QTest::mouseDClick(&bar, Qt::LeftButton, 0, tabPos); } +class Widget10052 : public QWidget +{ +public: + Widget10052(QWidget *parent) : QWidget(parent), moved(false) + { } + + void moveEvent(QMoveEvent *e) + { + moved = e->oldPos() != e->pos(); + QWidget::moveEvent(e); + } + + bool moved; +}; + +void tst_QTabBar::taskQTBUG_10052_widgetLayoutWhenMoving() +{ + QTabBar tabBar; + tabBar.insertTab(0, "My first tab"); + Widget10052 w1(&tabBar); + tabBar.setTabButton(0, QTabBar::RightSide, &w1); + tabBar.insertTab(1, "My other tab"); + Widget10052 w2(&tabBar); + tabBar.setTabButton(1, QTabBar::RightSide, &w2); + + tabBar.show(); + QTest::qWaitForWindowShown(&tabBar); + w1.moved = w2.moved = false; + tabBar.moveTab(0, 1); + QTRY_VERIFY(w1.moved); + QVERIFY(w2.moved); +} + QTEST_MAIN(tst_QTabBar) #include "tst_qtabbar.moc" |