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. TabViewStyle: make tabs take all horizontal space
Forum Updated to NodeBB v4.3 + New Features

TabViewStyle: make tabs take all horizontal space

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 2.3k 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.
  • E Offline
    E Offline
    Etchelon
    wrote on last edited by
    #1

    Hi

    I'm trying to understand how to make tabs in a TabView take all the available horizontal space. Setting their width is easy:
    @
    style: TabViewStyle {
    id: tabStyle

    frameOverlap: 1
    tab: Rectangle {
    color: styleData.selected ? "steelblue" :"lightsteelblue"
    border.color: "steelblue"
    implicitWidth: Math.max(text.width + 4, 80)
    implicitHeight: 60
    width: tabStyle.control.width / tabStyle.control.count

    radius: 2
    Text {
     id: text
     anchors.centerIn: parent
     text: tabStyle.control.width
     color: styleData.selected ? "white" : "black"
    }
    

    }
    frame: Rectangle { color: "red" }
    leftCorner: Rectangle { color: "cyan" }
    }
    @
    but I don't know how to change their position. tabsAlignment: Qt.AlignHCenter moves the tabs so that their left margin is in the middle of the tabBar... but they're stacked on each other, with the first one hiding the others...
    And I don't see which properties can be used to remedy.

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Etchelon
      wrote on last edited by
      #2

      Anyone?? This forum isn't very popular it seems... the majority of the threads has 0 replies.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jens
        wrote on last edited by
        #3

        I think it simply gets confused by you both setting implicitWidth and width. If you only set implicitWidth to tabStyle.control.width / tabStyle.control.count it works. The implicit width you have set is anyway not used since the tabs always fill the full width.

        1 Reply Last reply
        0
        • E Offline
          E Offline
          Etchelon
          wrote on last edited by
          #4

          [quote author="Jens" date="1403083037"]I think it simply gets confused by you both setting implicitWidth and width. If you only set implicitWidth to tabStyle.control.width / tabStyle.control.count it works. The implicit width you have set is anyway not used since the tabs always fill the full width.[/quote]
          Wow, a reply from one of the writers of QtQuick Controls, what a honor!
          Thanks for the reply Jens, but doing as u say doesn't work.
          https://github.com/Etchelon/VariousQmlTests
          I've uploaded the project (a Qt Quick Project, just 1 file + the .pro file) and pasted the code above, with your modification, and it doesn't work. Can you please look into it?

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jens
            wrote on last edited by
            #5

            The issue seems to be an indirect division by 0 and causes further updates to be ignored in this expression:
            @
            implicitWidth: control.width / control.count
            @

            The problem happens during initialization of the view, the count is initially 0. While the code as it stands should not really break, adding a safeguard will make the code evaluate correctly:

            @
            implicitWidth: control.width / Math.max(1, control.count)
            @

            1 Reply Last reply
            0
            • E Offline
              E Offline
              Etchelon
              wrote on last edited by
              #6

              That's it! Many thanks :)

              1 Reply Last reply
              0

              • Login

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