Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Saving Index of TabBar
Forum Updated to NodeBB v4.3 + New Features

Saving Index of TabBar

Scheduled Pinned Locked Moved Solved QML and Qt Quick
10 Posts 4 Posters 540 Views 4 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    My app has two levels of TabBar. The model for the 2nd level changes with selections from the primary TabBar.

    home.PNG
    settings.PNG

    How can I save the index for the 2nd level TabBar when I switch models? So, if under "Home" I was on "Pool", I could return to "Pool" after navigating away from, and back to "Home." Currently it resets to "All Site."

    Thanks...

    SGaistS 1 Reply Last reply
    0
    • mzimmersM mzimmers

      @Shrinidhi-Upadhyaya thank you for the creative solution.

      @SGaist I'd like to hear more about your suggestion.

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #10

      @mzimmers again in terms of widgets, think of a set of QTabBar stored in a QStackedWidget.

      It might be doable with a StackView.

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

      1 Reply Last reply
      1
      • mzimmersM mzimmers

        Hi all -

        My app has two levels of TabBar. The model for the 2nd level changes with selections from the primary TabBar.

        home.PNG
        settings.PNG

        How can I save the index for the 2nd level TabBar when I switch models? So, if under "Home" I was on "Pool", I could return to "Pool" after navigating away from, and back to "Home." Currently it resets to "All Site."

        Thanks...

        SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @mzimmers hi,

        How did you implement the switch between sub-tabbar ?

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

        mzimmersM 1 Reply Last reply
        0
        • SGaistS SGaist

          @mzimmers hi,

          How did you implement the switch between sub-tabbar ?

          mzimmersM Offline
          mzimmersM Offline
          mzimmers
          wrote on last edited by
          #3

          @SGaist like this:

          Auxtabbar {
              id: auxtabbar
              height: 48.0
                  id: prefsModel
                  ListElement { name: "Profile && Accounts" }
                  ListElement { name: "Device" }
                  ListElement { name: "Site" }
              }
          
              Repeater {
                  model: (mainTabBar.tabIndex < 4) ? zoneModel : prefsModel
                  Tabbutton_custom {
                      text: qsTr(model.name)
                  }
              }
          }
          
          SGaistS 1 Reply Last reply
          0
          • mzimmersM mzimmers

            @SGaist like this:

            Auxtabbar {
                id: auxtabbar
                height: 48.0
                    id: prefsModel
                    ListElement { name: "Profile && Accounts" }
                    ListElement { name: "Device" }
                    ListElement { name: "Site" }
                }
            
                Repeater {
                    model: (mainTabBar.tabIndex < 4) ? zoneModel : prefsModel
                    Tabbutton_custom {
                        text: qsTr(model.name)
                    }
                }
            }
            
            SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @mzimmers rather than changing models, wouldn't it be simpler to consider each tab bar as a whole "widget" ?

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

            mzimmersM 1 Reply Last reply
            0
            • SGaistS SGaist

              @mzimmers rather than changing models, wouldn't it be simpler to consider each tab bar as a whole "widget" ?

              mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by
              #5

              @SGaist I'm not sure I understand. The auxiliary tab bar I'm implementing may have a variable number of tabs, so I can't hard-code them.

              I can already see some pitfalls in my approach, though, so I'm definitely open to suggestions.

              1 Reply Last reply
              0
              • Shrinidhi UpadhyayaS Offline
                Shrinidhi UpadhyayaS Offline
                Shrinidhi Upadhyaya
                wrote on last edited by
                #6

                Here is the sample code:-

                ListModel {
                        id: topBarModel
                
                        ListElement {
                            text: "Home"
                            currentSubIndex: 0
                        }
                
                        ListElement {
                            text: "Equipment"
                            currentSubIndex: 0
                        }
                
                        ListElement {
                            text: "Activity"
                            currentSubIndex: 0
                        }
                
                        ListElement {
                            text: "Service"
                            currentSubIndex: 0
                        }
                    }
                
                    ListModel {
                        id: bottomBarModel
                
                        ListElement {
                            text: "Profile"
                        }
                
                        ListElement {
                            text: "Device"
                        }
                
                        ListElement {
                            text: "Site"
                        }
                    }
                
                    TabBar {
                        id: topBar
                
                        width: parent.width
                        height: 50
                        spacing: 0
                
                        Repeater {
                            model: topBarModel
                            TabButton {
                                text: model.text
                                width: Math.max(100, topBar.width / 4)
                
                                contentItem: Text {
                                       text: model.text
                                       opacity: enabled ? 1.0 : 0.3
                                       color: "#17a81a"
                                       horizontalAlignment: Text.AlignHCenter
                                       verticalAlignment: Text.AlignVCenter
                                       elide: Text.ElideRight
                                   }
                
                                background: Rectangle {
                                    color: "transparent"
                
                                    Rectangle {
                                        width: parent.width
                                        height: 2
                                        anchors.bottom: parent.bottom
                                        color: "purple"
                                        visible: topBar.currentIndex === index
                                    }
                                }
                            }
                        }
                    }
                
                    TabBar {
                        id: bottomBar
                
                        width: parent.width
                        height: 50
                        anchors.top: topBar.bottom
                        spacing: 0
                        currentIndex: topBarModel.get(topBar.currentIndex).currentSubIndex
                
                        Repeater {
                            model: bottomBarModel
                
                            TabButton {
                                text: model.text
                                width: Math.max(100, bottomBar.width / 3)
                
                                contentItem: Text {
                                       text: model.text
                                       opacity: enabled ? 1.0 : 0.3
                                       color: "#17a81a"
                                       horizontalAlignment: Text.AlignHCenter
                                       verticalAlignment: Text.AlignVCenter
                                       elide: Text.ElideRight
                                   }
                
                                background: Rectangle {
                                    color: "transparent"
                
                                    Rectangle {
                                        width: parent.width
                                        height: 2
                                        anchors.bottom: parent.bottom
                                        color: "purple"
                                        visible: bottomBar.currentIndex === index
                                    }
                                }
                
                                onClicked: {
                                    topBarModel.setProperty(topBar.currentIndex, "currentSubIndex", index)
                                }
                            }
                        }
                    }
                

                Output:-

                3c6468db-cf57-4212-8965-76b6f9aab6a8-image.png

                Shrinidhi Upadhyaya.
                Upvote the answer(s) that helped you to solve the issue.

                piervalliP 1 Reply Last reply
                1
                • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

                  Here is the sample code:-

                  ListModel {
                          id: topBarModel
                  
                          ListElement {
                              text: "Home"
                              currentSubIndex: 0
                          }
                  
                          ListElement {
                              text: "Equipment"
                              currentSubIndex: 0
                          }
                  
                          ListElement {
                              text: "Activity"
                              currentSubIndex: 0
                          }
                  
                          ListElement {
                              text: "Service"
                              currentSubIndex: 0
                          }
                      }
                  
                      ListModel {
                          id: bottomBarModel
                  
                          ListElement {
                              text: "Profile"
                          }
                  
                          ListElement {
                              text: "Device"
                          }
                  
                          ListElement {
                              text: "Site"
                          }
                      }
                  
                      TabBar {
                          id: topBar
                  
                          width: parent.width
                          height: 50
                          spacing: 0
                  
                          Repeater {
                              model: topBarModel
                              TabButton {
                                  text: model.text
                                  width: Math.max(100, topBar.width / 4)
                  
                                  contentItem: Text {
                                         text: model.text
                                         opacity: enabled ? 1.0 : 0.3
                                         color: "#17a81a"
                                         horizontalAlignment: Text.AlignHCenter
                                         verticalAlignment: Text.AlignVCenter
                                         elide: Text.ElideRight
                                     }
                  
                                  background: Rectangle {
                                      color: "transparent"
                  
                                      Rectangle {
                                          width: parent.width
                                          height: 2
                                          anchors.bottom: parent.bottom
                                          color: "purple"
                                          visible: topBar.currentIndex === index
                                      }
                                  }
                              }
                          }
                      }
                  
                      TabBar {
                          id: bottomBar
                  
                          width: parent.width
                          height: 50
                          anchors.top: topBar.bottom
                          spacing: 0
                          currentIndex: topBarModel.get(topBar.currentIndex).currentSubIndex
                  
                          Repeater {
                              model: bottomBarModel
                  
                              TabButton {
                                  text: model.text
                                  width: Math.max(100, bottomBar.width / 3)
                  
                                  contentItem: Text {
                                         text: model.text
                                         opacity: enabled ? 1.0 : 0.3
                                         color: "#17a81a"
                                         horizontalAlignment: Text.AlignHCenter
                                         verticalAlignment: Text.AlignVCenter
                                         elide: Text.ElideRight
                                     }
                  
                                  background: Rectangle {
                                      color: "transparent"
                  
                                      Rectangle {
                                          width: parent.width
                                          height: 2
                                          anchors.bottom: parent.bottom
                                          color: "purple"
                                          visible: bottomBar.currentIndex === index
                                      }
                                  }
                  
                                  onClicked: {
                                      topBarModel.setProperty(topBar.currentIndex, "currentSubIndex", index)
                                  }
                              }
                          }
                      }
                  

                  Output:-

                  3c6468db-cf57-4212-8965-76b6f9aab6a8-image.png

                  piervalliP Offline
                  piervalliP Offline
                  piervalli
                  wrote on last edited by
                  #7

                  @Shrinidhi-Upadhyaya

                  if I understand well there a cascade of events,
                  You should save only the first event

                  Find in doc Settings class

                  mzimmersM 1 Reply Last reply
                  0
                  • piervalliP piervalli

                    @Shrinidhi-Upadhyaya

                    if I understand well there a cascade of events,
                    You should save only the first event

                    Find in doc Settings class

                    mzimmersM Offline
                    mzimmersM Offline
                    mzimmers
                    wrote on last edited by
                    #8

                    @Shrinidhi-Upadhyaya thank you for the creative solution.

                    @SGaist I'd like to hear more about your suggestion.

                    piervalliP SGaistS 2 Replies Last reply
                    0
                    • mzimmersM mzimmers

                      @Shrinidhi-Upadhyaya thank you for the creative solution.

                      @SGaist I'd like to hear more about your suggestion.

                      piervalliP Offline
                      piervalliP Offline
                      piervalli
                      wrote on last edited by
                      #9

                      @mzimmers
                      Nice Communicty

                      1 Reply Last reply
                      0
                      • mzimmersM mzimmers

                        @Shrinidhi-Upadhyaya thank you for the creative solution.

                        @SGaist I'd like to hear more about your suggestion.

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        @mzimmers again in terms of widgets, think of a set of QTabBar stored in a QStackedWidget.

                        It might be doable with a StackView.

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

                        1 Reply Last reply
                        1
                        • mzimmersM mzimmers has marked this topic as solved on

                        • Login

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