Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved how to determine active tab in TabBar?

    QML and Qt Quick
    1
    2
    65
    Loading More Posts
    • 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.
    • mzimmers
      mzimmers last edited by mzimmers

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

      1 Reply Last reply Reply Quote 0
      • mzimmers
        mzimmers last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post