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 StackView

    Item {
      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 item

    Item {
      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 model

    ListView {
      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.


  • Moderators

    @literA2

    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


  • Moderators

    @literA2

    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!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.