Qt 6.11 is out! See what's new in the release
blog
How to select QTab ? (in C code )
-
After much searching I realized that adding QFrame makes for easy duplicating but it is hard to iterate.
Now I have this simple code iterating all QTab...
But I cannot figure out How to activate / select specific QTab.
// iterate - show all tab text for(int tabIndex = 0; tabIndex < ui->tabWidget_15->count(); tabIndex++) { qDebug( ) <<"iterate @ index " << QString::number(tabIndex); qDebug() <<"tab text @ index " << QString::number(tabIndex)<< ui->tabWidget_15->tabText(tabIndex) ; // select as current tab / QWidget // ui->tabWidget_15->widget(tabIndex)->????? ui->tabWidget_15->widget(tabIndex)->activateWindow(); // no go ui->tabWidget_15->widget(tabIndex)->focusWidget(); // no go ui->tabWidget_15->widget(tabIndex)->setFocus(); // no go ui->tabWidget_15->widget(tabIndex)->setEnabled(true); // no go // TabWidget } -
I assume that:
- tabWidget_15 is a QTabWidget
- with "activate / select" you mean setting the currentIndex of the tabWidget, i.e. determining which tab is being shown.
If that is the case, look here.
const int tabIndexToShow = 42; // or whatever you want ui->tabWidget_15->setCurrentIndex(tabIndexToShow);...that should do what you want.
-
Thanks for the idea.
Looks convoluted , but works as expected.
ui->tabWidget_15->setCurrentWidget(ui->tabWidget_15->widget(tabIndex));SOLVED