Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. QML: TabBar and StackLayout
Forum Updated to NodeBB v4.3 + New Features

QML: TabBar and StackLayout

Scheduled Pinned Locked Moved Solved Brainstorm
9 Posts 2 Posters 2.5k Views 1 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.
  • M Offline
    M Offline
    mzimmers
    wrote on 26 Oct 2022, 18:32 last edited by mzimmers
    #1

    Hi all -

    I'm trying to use StackLayouts to display various components based on a selected tab. The docs on StackLayout are somewhat brief, but seem clear. But...they're not doing what I expected; might be a misunderstaning on my part.

    Am I correct in that the components in the StackLayout can fill the entire area under the tab bar?

    Here's my code. You'll notice that the StackLayout isn't a peer of the TabBar, but that doesn't appear to be causing a problem. So, I guess my question is, why am I not getting a big yellow rectangle under the TabBar?

    Thanks...

    EDIT:

    I guess it would help if I actually posted the code snippet:

    ColumnLayout {
    
        Rectangle {
            height: parent.height
            width: parent.width
            Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
    
            TabBar {}
            Row  {}
        }
    
        StackLayout {
            Layout.fillHeight: true
            Layout.fillWidth: true
            Item {
                Rectangle {
                    Layout.fillHeight: true
                    Layout.fillWidth: true
                    color: 'yellow'
                }
    		etc.
    
    1 Reply Last reply
    0
    • J Offline
      J Offline
      JoeCFD
      wrote on 26 Oct 2022, 18:36 last edited by JoeCFD
      #2

      https://asitdhal.medium.com/stacklayout-in-qml-2ddeafa09ae5
      anchors settings are the keys

      M 1 Reply Last reply 26 Oct 2022, 18:51
      0
      • J JoeCFD
        26 Oct 2022, 18:36

        https://asitdhal.medium.com/stacklayout-in-qml-2ddeafa09ae5
        anchors settings are the keys

        M Offline
        M Offline
        mzimmers
        wrote on 26 Oct 2022, 18:51 last edited by
        #3

        @JoeCFD I can't use anchors as coded. I did use Layout fills (as indicated in the code I added) -- shouldn't that suffice?

        J 1 Reply Last reply 26 Oct 2022, 19:01
        0
        • M mzimmers
          26 Oct 2022, 18:51

          @JoeCFD I can't use anchors as coded. I did use Layout fills (as indicated in the code I added) -- shouldn't that suffice?

          J Offline
          J Offline
          JoeCFD
          wrote on 26 Oct 2022, 19:01 last edited by
          #4

          @mzimmers what did you get with your layout?

          M 1 Reply Last reply 26 Oct 2022, 19:23
          0
          • J JoeCFD
            26 Oct 2022, 19:01

            @mzimmers what did you get with your layout?

            M Offline
            M Offline
            mzimmers
            wrote on 26 Oct 2022, 19:23 last edited by mzimmers
            #5

            @JoeCFD said in QML: TabBar and StackLayout:

            @mzimmers what did you get with your layout?

            With my Item Rectangles using the above Layout directives, I get ca-ca. It also blows up my toolbar -- I'm missing some items, and my background color is gone. No error messages, though.

            When I define the rectangles with fixed height and width, it works OK, but that's not what I want.

            EDIT:

            I misspoke above: the presence of the StackLayout messes with my Rectangle containing the TabBar.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mzimmers
              wrote on 26 Oct 2022, 19:47 last edited by
              #6

              I think I could make this simpler if I can put my TabBar and my StackLayout in separate files. If I do this, though, how do I connect the TabBar currentIndex to my StackLayout?

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JoeCFD
                wrote on 26 Oct 2022, 20:21 last edited by
                #7

                id is your friend.

                M 1 Reply Last reply 26 Oct 2022, 20:47
                0
                • J JoeCFD
                  26 Oct 2022, 20:21

                  id is your friend.

                  M Offline
                  M Offline
                  mzimmers
                  wrote on 26 Oct 2022, 20:47 last edited by mzimmers
                  #8

                  @JoeCFD I figured any answer to this would involve ids, but...

                  main.qml:

                  ColumnLayout {
                      Navbar {
                          id: navBar
                      }
                      Mainarea {}
                      }
                  

                  Navbar.qml:

                  ColumnLayout {
                      id: fullScreen
                      Rectangle {
                          id: navBar
                          TabBar {
                              id: navTabs
                  etc.
                  

                  How do I get the value of the navTabs.currentIndex so that I can pass it to Mainarea?

                  EDIT:

                  This last question deserves its own thread. Please disregard. I'm keeping this thread open because I know I'll have more questions.

                  Thanks...

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mzimmers
                    wrote on 27 Oct 2022, 17:20 last edited by
                    #9

                    OK, I got it figured out. As @JoeCFD suggested, I needed anchors instead of Layout.*. Someday, I'll commit this to memory -- @fcarney will probably only have to remind me another 100 times...

                    Thanks for the help.

                    1 Reply Last reply
                    0

                    1/9

                    26 Oct 2022, 18:32

                    • Login

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