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. how to make TabBar fill horizontally?
Forum Updated to NodeBB v4.3 + New Features

how to make TabBar fill horizontally?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 729 Views 2 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 mzimmers
    #1

    Hi all -

    I need to make a tab bar span the width of its parent. Here's my sample code:

    import QtQuick
    import QtQuick.Controls 2.15
    import QtQuick.Controls.Material 2.15
    import QtQuick.Layouts 1.15
    
    
    Window {
        width: 640
        height: 480
        visible: true
    
        ColumnLayout {
            Layout.fillWidth: true
            TabBar {
                id: bar
                width: parent.width
                Layout.fillWidth: true
                TabButton {
                    text: qsTr("red")
                }
                TabButton {
                    text: qsTr("green")
                }
                TabButton {
                    text: qsTr("blue")
                }
            }
    
            StackLayout {
                width: parent.width
                currentIndex: bar.currentIndex
                Item {
                    Rectangle {
                        height: 100
                        width: 100
                        color: 'red'
                    }
                }
                Item {
                    Rectangle {
                        height: 100
                        width: 100
                        color: 'green'
                    }
                }
                Item {
                    Rectangle {
                        height: 100
                        width: 100
                        color: 'blue'
                    }
                }
            }
        }
    }
    

    And here's what I'm getting:
    tabbar.PNG
    Can someone see what I'm doing wrong here?

    Thanks...

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      @mzimmers said in how to make TabBar fill horizontally?:

      ColumnLayout {
      Layout.fillWidth: true

      Layout only works for Items inside a layout. Window is not a layout. ColumnLayout is not inside a layout.

      ColumnLayout {
        width: parent.width
      

      C++ is a perfectly valid school of magic.

      mzimmersM 1 Reply Last reply
      1
      • fcarneyF fcarney

        @mzimmers said in how to make TabBar fill horizontally?:

        ColumnLayout {
        Layout.fillWidth: true

        Layout only works for Items inside a layout. Window is not a layout. ColumnLayout is not inside a layout.

        ColumnLayout {
          width: parent.width
        
        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        @fcarney OK, that makes sense, and your fix works fine on my minimal test app:testapp.PNG
        (I added a ToolBar above my TabBar.)

        When I try to transfer this to my "real" app, though, I run into some problems:realapp.PNG

        In my "real" app, I put the ToolBar code in its own file:

        ColumnLayout {
            width: parent.width
            TabBar {
                id: bar
                Layout.fillWidth: true
                height: 48
                TabButton {
                    text: qsTr("1")
                    onClicked: console.log("index is " + bar.currentIndex)
                }
                TabButton {
                    text: qsTr("2")
                    onClicked: console.log("index is " + bar.currentIndex)
                }
                TabButton {
                    text: qsTr("3")
                    onClicked: console.log("index is " + bar.currentIndex)
                }
            }
        
            StackLayout {
                width: parent.width
                ...
        

        So, 1) why am I not getting the desired TabBar height of 48, and 2) how did I happen to define the borders that I'm seeing (not that I don't like them, but they weren't in the test app)?

        Thanks...

        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #4

          @mzimmers said in how to make TabBar fill horizontally?:

          height: 48

          Layouts require hints or whatever they are called. There are a bunch defined in Layout

          For example:

          Layouts.mimimumHeight: 48
          

          The different looking buttons sounds like a style issue. Somewhere you are selecting a particular style in your real app?

          C++ is a perfectly valid school of magic.

          1 Reply Last reply
          1
          • mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            So...my app has 3 "rows" (for lack of a better term):

            1. toolbar
            2. tabbar
            3. stack layout

            I remember in an earlier post, you said that Layout.* isn't applied directly to a Layout. So, is the minimumHeight property applied to the items in the layout?

            BTW: should "Layouts.mimimumHeight" be "Layout.mimimumHeight?"

            Thanks...

            1 Reply Last reply
            0
            • fcarneyF Offline
              fcarneyF Offline
              fcarney
              wrote on last edited by
              #6

              Layout.<whatever> is only used inside Items that are children of some layout type. They direct the parent layout how to treat the child.
              https://doc.qt.io/qt-5/qtquicklayouts-index.html

              C++ is a perfectly valid school of magic.

              1 Reply Last reply
              1

              • Login

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