Important: Please read the Qt Code of Conduct -

How to get currentTabName from QTabWidget on Qt?

  • QTabWidget has a property called currentTabName.

    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

  • Lifetime Qt Champion


    Where did you see that property ?

    Why do you need to check which tab is selected and particularly why by its name ?

  • @SGaist, I found the property here:

    alt text

    I want to access the tab by a value that will be not changed in the future. The text and the index may be changed.

    I have a button that calls a function that loads a new window based on the selected tab (this new window is used only to show some tips about the currently opened tab), so I need to check what tab is currently selected.

    For example:

    alt text

  • Moderators

    This is the object name of the current widget. From code you'd get it like this:

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

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

  • @Chris-Kawa thanks a lot. This is exactly what I was looking for.

Log in to reply