[SOLVED]How to refresh TabText dynamically?
-
I have a QTabWidget and want to refresh the tab names dynamically. E.g., TabWidget has Tab1, Tab2, Tab3, Tab4 at the beginning. Then I close Tab2, the three Tab names should become Tab1, Tab2, Tab3.
Now, I try to do it like follows:
@ setUpdatesEnabled(true);
for (int i = index; i < displayTabWidget->count(); i++) {
tabName = "Curves";
tabName += QString::number(i);
setTabText(i, tabName);
}
displayTabWidget->repaint();@I put it inside the function closeTab(int index) and after removeTab(index) is called
But this does not work...The Tab texts do not change
Thanks a lot!
-
Hi, I've created a small MainWindow for you for that your code is working. Especially have a look on how you are using the setTabText function, without an object. Possibly you have derived your class from QTabWidget and mix some things up?
@MainWindow::MainWindow(QWidget parent) :
QMainWindow(parent)
{
QTabWidget tabWidget = new QTabWidget(this);
setCentralWidget(tabWidget);tabWidget->addTab(new QWidget, "Tab 1");
tabWidget->addTab(new QWidget, "Tab 2");
tabWidget->addTab(new QWidget, "Tab 3");for (int i = 0; i < tabWidget->count(); i++) {
QString tabName = "Curves";
tabName += QString::number(i);
tabWidget->setTabText(i, tabName);
}
}
@