summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/widgets/qtabbar.cpp3
-rw-r--r--tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp23
2 files changed, 26 insertions, 0 deletions
diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp
index dfd1f1022c..b47d65f561 100644
--- a/src/widgets/widgets/qtabbar.cpp
+++ b/src/widgets/widgets/qtabbar.cpp
@@ -1681,6 +1681,7 @@ void QTabBar::moveTab(int from, int to)
d->tabList[i].lastTab = d->calculateNewPosition(from, to, d->tabList[i].lastTab);
// update external variables
+ int previousIndex = d->currentIndex;
d->currentIndex = d->calculateNewPosition(from, to, d->currentIndex);
// If we are in the middle of a drag update the dragStartPosition
@@ -1699,6 +1700,8 @@ void QTabBar::moveTab(int from, int to)
d->layoutWidgets(start);
update();
emit tabMoved(from, to);
+ if (previousIndex != d->currentIndex)
+ emit currentChanged(d->currentIndex);
emit tabLayoutChange();
}
diff --git a/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp b/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp
index fa518e6afd..e6fe5f92c7 100644
--- a/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp
+++ b/tests/auto/widgets/widgets/qtabwidget/tst_qtabwidget.cpp
@@ -112,6 +112,7 @@ class tst_QTabWidget:public QObject {
void heightForWidth_data();
void heightForWidth();
void tabBarClicked();
+ void moveCurrentTab();
private:
int addPage();
@@ -709,5 +710,27 @@ void tst_QTabWidget::tabBarClicked()
}
}
+void tst_QTabWidget::moveCurrentTab()
+{
+ QTabWidget tabWidget;
+ QWidget* firstTab = new QWidget(&tabWidget);
+ QWidget* secondTab = new QWidget(&tabWidget);
+ tabWidget.addTab(firstTab, "0");
+ tabWidget.addTab(secondTab, "1");
+
+ QCOMPARE(tabWidget.currentIndex(), 0);
+ QCOMPARE(tabWidget.currentWidget(), firstTab);
+
+ tabWidget.setCurrentIndex(1);
+
+ QCOMPARE(tabWidget.currentIndex(), 1);
+ QCOMPARE(tabWidget.currentWidget(), secondTab);
+
+ tabWidget.tabBar()->moveTab(1, 0);
+
+ QCOMPARE(tabWidget.currentIndex(), 0);
+ QCOMPARE(tabWidget.currentWidget(), secondTab);
+}
+
QTEST_MAIN(tst_QTabWidget)
#include "tst_qtabwidget.moc"