SwipeView and TabBar currentIndex issue when dynamic object creation
Solved
QML and Qt Quick
-
Hi,
I am using Qt 5.15.0 and trying to load some tabs dynamically on SwipeView before using it on my project. But unfortunately, I am facing an issue with currentIndex of SwipeView and TabBar that it doesn't increment at all. So, the Rectangle area will remain always red instead of switching colors between red and green.
Am I doing something wrong with my QML example? Am I missing something how to connect SwipeView and TabBar? Please check my QML example below.
Thanks!
import QtQuick 2.12 import QtQuick.Controls 2.12 ApplicationWindow { width: 640 height: 480 visible: true title: qsTr("Tabs") Component { id: resultListView Rectangle { color: "blue" } } Component { id: tabButton TabButton { width: implicitWidth } } SwipeView { id: swipeView anchors.fill: parent currentIndex: tabBar.currentIndex } footer: TabBar { id: tabBar currentIndex: swipeView.currentIndex } Component.onCompleted: { for (var i = 0; i < 5; i++) { console.log("tabBar currentIndex: ", tabBar.currentIndex) console.log("stack currentIndex: ", swipeView.currentIndex) // Add TabButtons dynamically on TabBar tabBar.addItem(tabButton.createObject(tabBar, {text: qsTr("tab - " + (tabBar.count))} ) ) var col = "green"; if (tabBar.currentIndex % 2 === 0) { col = "red"; } console.log("tabBar color: ", col) swipeView.addItem(resultListView.createObject(swipeView, {color: col})) } } }