Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how to determine active tab in TabBar?



  • Hi all -

    A view in my app uses a TabBar with three TabButtons:

    TabBar {
      property var tabNames: ["TabOne", "TabTwo", "TabThree"]
    
      Repeater {
        model: tabNames
        
        TabButton {
          id: tabButton
          text: tabNames[index]
    

    Which produces this lovely display:
    tabbar.PNG

    The legend at the lower right should only display when the first tab ("Yield") is selected. The original programmer attempted to do this with a property:

    Q_PROPERTY(bool viewingTheYield READ ViewingTheYield NOTIFY EventViewingTheYieldChanged)
    bool PlateNavigation::ViewingTheYield() const {
      return m_viewingTheYield;
    }
    

    If the user clicks on one of the other tabs, the legend disappears (as it should). But, if the user then loads a new report, this display returns to the last tab the previous report had selected (which it shouldn't). Somehow I need to control which tab is active...how do I do that? I can't find anything in the docs about it.

    Thanks...



  • Sigh...I love when I find the answer immediately after posting...

    Container currentIndex

    TabBar {
      id: root
      currentIndex: {
          if (plateNavViewModel.viewingTheYield) {
              0
          } else {
              2
          }
      }
    

    I know the hard-coding is bad, but...it works.


Log in to reply