Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get currentTabName from QTabWidget on Qt?
Forum Updated to NodeBB v4.3 + New Features

How to get currentTabName from QTabWidget on Qt?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 14.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KelvinSP
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Where did you see that property ?

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Where did you see that property ?

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

        K Offline
        K Offline
        KelvinSP
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by Chris Kawa
          #4

          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().

          K 1 Reply Last reply
          2
          • Chris KawaC Chris Kawa

            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().

            K Offline
            K Offline
            KelvinSP
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved