Unsolved TabButton implicitWidth Strange Behaviour (in TabBar)
-
Hi. How come in this code the
implicitWidth
ofTabBar
changes when I comment outwidth: implicitWidth
inTabButton
s? (I am trying to create a verticalTabBar
) Why does the fact that I am settingwidth
of a component to be itsimplicitWidth
(which I assumed was the default behavior anyway whenwidth
is not set) change theimplicitWidth
? You can run this example withqmlscene
:import QtQuick 2.15 import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 Item { id: root height: 480 width: 640 RowLayout { anchors.fill: parent TabBar { id: bar Layout.fillHeight: true implicitWidth: Math.max(homeTabButton.implicitWidth, discoverTabButton.implicitWidth, activityTabButton.implicitWidth) background: Rectangle { color: "yellow" } contentItem: ListView { // orientation: ListView.Horizontal model: bar.contentModel } TabButton { id: homeTabButton width: implicitWidth text: qsTr("Home") } TabButton { id: discoverTabButton width: implicitWidth text: qsTr("Discover") } TabButton { id: activityTabButton width: implicitWidth text: qsTr("Activity") } } StackLayout { Layout.fillWidth: true Layout.fillHeight: true currentIndex: bar.currentIndex Pane { id: homeTab background: Rectangle { color: "blue" } } Pane { id: discoverTab background: Rectangle { color: "red" } } Pane { id: activityTab background: Rectangle { color: "green" } } } } }
-
I have created a SO question as well in case someone wants to answer there instead:
https://stackoverflow.com/questions/64267727/qml-why-does-tabbars-implicitwidth-depend-on-binding-inner-tabbuttons-width/64330266