Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get currentTabName from QTabWidget on Qt?

Tags:

c++

qt

qtabwidget

QTabWidget has a property called currentTabName.

enter image description here

How can I access the currentTabName by code?

I need to check what tab is selected, but I can't use the tab text (tabText) because it is translatable and may change and I don't want to use the tab index (currentIndex) because the index may change in the future.

I'm using Qt 5.3

like image 418
KelvinS Avatar asked Nov 18 '25 01:11

KelvinS


1 Answers

As Chris Kawa answered here this is the object name of the current widget.

From code I can get it like this:

QString currentTabName = tabWidget->currentWidget()->objectName();

Note: As the doc suggest make sure to check for nullptr when using tabWidget->currentWidget().

like image 174
KelvinS Avatar answered Nov 20 '25 17:11

KelvinS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!