access to swipeview children from outside of it
Unsolved
QML and Qt Quick
-
Hi, I want to have a rectangle located on a swipeview and it should load different qml pages when swipeview index changes. please have look at following code:
Item { SwipeView { id: swipView currentIndex: 0 anchors.fill: parent Repeater { model: 3 Page { id: delegate Button { text: "<" width: 18 height: 40 enabled: index > 0 onClicked: { delegate.SwipeView.view.decrementCurrentIndex() } anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter } Button { text: ">" width: 18 height: 40 enabled: index < delegate.SwipeView.view.count - 1 onClicked: { delegate.SwipeView.view.incrementCurrentIndex() } anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter } Rectangle { id: pgRect state: "blue" anchors { left: parent.left top: parent.top leftMargin: 18 topMargin: 18 rightMargin: 18 bottomMargin: 18 fill: parent } Loader { id: loader anchors.fill: parent } Connections { target: loader.source != "" ? loader.item : null } states: [ State { name: "page1" PropertyChanges { target: loader source: "PageI.qml" } }, State { name: "page2" PropertyChanges { target: loader source: "PageII.qml" } }, State { name: "page3" PropertyChanges { target: loader source: "PageIII.qml" } } ] } } } onCurrentIndexChanged: { if(swipView.currentIndex === 0) { // change pgRect.state } } } }
i want to have access to rectangle properties and change its state (changing the qml page loaded on rectangle) in onCurrentIndexChanged signal.
but it says: pgRect is not defined. -
Modify the Repeater as
Repeater{ id : rep1 Page { property alias myrect : pgrect
Access each element inside the repeater using rep1.itemAt(index).