Solved how to capture signal from pop item in Stackview
-
Hi,
Is there a way to capture a signal from pop items in StackView?
I am trying to implement an custom select element, this is how I implement it.
Page1.qml
the parent of this page has a StackViewItem { Component.onCompleted { textSelect.setValue("en"); } CustomSelect { id: textSelect model: ListModel { ListElement { item: "English" value: "en" icon: "flag-en.png" } ListElement { item: "German" value: "de" icon: "flag-de.png" } } onClicked: { mainStack.push({item:Qt.resolvedUrl("CustomSelectItems.qml"), properties:{listModel: textSelect.model, currentIndex: textSelect.currentIndex}}) } } }
CustomSelect.qml
displays the current selected itemItem { id: select property ListModel model property int currentIndex signal clicked() function setValue(value) { for (var i=0; i<select.model.count; ++i) { if (model.get(i).value === value) { select.currentIndex = i; break; } } } Row { Image { id: icon source: select.model.get(select.currentIndex).icon } Text { id: value text: select.model.get(select.currentIndex).item } } MouseArea { anchors.fill: parent onClicked: { select.clicked() } } }
Is it possible to capture a signal from CustomSelectItems once popped? so that the CustomSelect currentIndex from Page1 will be updated?
CustomSelectItems.qml
used to display items from the modelListView { id: selectList property alias listModel: selectList.model property alias currentIndex: selectList.currentIndex signal clicked() delegate: Row { Image { id: icon source: model.icon } Text { id: value text: model.item } } }
Is my implementation possible? Please feel free to correct my implementation and advise what is the possible solution for this. Thanks.
-
Is it possible to capture a signal from CustomSelectItems once popped? so that the CustomSelect currentIndex from Page1 will be updated?
The
pop
function returns the item which is popped. Won't that be useful ? -
@p3c0 thanks for the reply.
Sorry, can you please advise how to get the returned item and its signal. Thanks
-
var currentItem = stack.pop() ... currentItem.mySignal.connect(onMySignal) //mySignal is the signal in currentItem //onMySignal is a JS function
-
@p3c0 Thank you very much! Please considered this SOLVED!
-
@literA2 how does Page1.qml has access to mainStack? I need this functionality in my app too. Navigation within the stackview pages.