I have multiple tabs in an application using Qt and I add them all to a QVBoxLayout
object. How to know which one is selected?
Asked
Active
Viewed 9,330 times
2
2 Answers
9
QTabWidget::currentIndex()
will return the index of the active tab.

dtech
- 47,916
- 17
- 112
- 190
-
should I use it exactly like or using the Tab object because I already tried it like objTab->(..) there no currenIndex method ?? – Engine Feb 27 '13 at 09:14
-
@Engine - no, this is the actual method, you will use that on your instance. If you have a Designer UI form you will need to do something like `ui->myTabWidget.currentIndex()` or without the `ui->` if you instantiate the user interface programmatically. – dtech Feb 27 '13 at 09:17
-
1It's a method of QTabWidget, not of individual tabs. – Frank Osterfeld Feb 27 '13 at 09:54
1
I prefer ui->QTabWidget->currentWidget() == ui->Tab
In case you rearrange your tabs and the index changes.

Jason
- 41
- 4