Why in the following code implicitWidth
of TabBar
changes when I comment out width: implicitWidth
in TabButton
s? Why does the fact that I am setting width
of a component to be equal to its implicitWidth
change the implicitWidth
?
Also, I thought width
was set to implicitWidth
by default anyways when width
is not explicitly set. So I don't understand why doing width: implicitWidth
would have any effects. Here is the code:
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 {
model: bar.contentModel
}
TabButton {
id: homeTabButton
width: implicitWidth // I cannot comment this out
text: qsTr("Home")
}
TabButton {
id: discoverTabButton
width: implicitWidth // I cannot comment this out
text: qsTr("Discover")
}
TabButton {
id: activityTabButton
width: implicitWidth // I cannot comment this out
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"
}
}
}
}
}
U have assigned an implicit width before
that's why when u comment width in tabButton it taking width as 0.
use
in your code and comment that width in tabButton ans see.