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?

How to get currentTabName from QTabWidget on Qt?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 14.3k Views
  • 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 30 Jun 2017, 20:46 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 30 Jun 2017, 20:58 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 30 Jun 2017, 21:09
      0
      • S SGaist
        30 Jun 2017, 20:58

        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 30 Jun 2017, 21:09 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
        • C Offline
          C Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on 30 Jun 2017, 21:13 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 30 Jun 2017, 21:21
          2
          • C Chris Kawa
            30 Jun 2017, 21:13

            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 30 Jun 2017, 21:21 last edited by
            #5

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

            1 Reply Last reply
            0

            4/5

            30 Jun 2017, 21:13

            • Login

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