Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. how to capture signal from pop item in Stackview
Forum Update on Monday, May 27th 2025

how to capture signal from pop item in Stackview

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 2.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    literA2
    wrote on last edited by p3c0
    #1

    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.

    p3c0P J 2 Replies Last reply
    0
    • L literA2

      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.

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @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 ?

      157

      L 1 Reply Last reply
      0
      • p3c0P p3c0

        @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 ?

        L Offline
        L Offline
        literA2
        wrote on last edited by
        #3

        @p3c0 thanks for the reply.

        Sorry, can you please advise how to get the returned item and its signal. Thanks

        p3c0P 1 Reply Last reply
        0
        • L literA2

          @p3c0 thanks for the reply.

          Sorry, can you please advise how to get the returned item and its signal. Thanks

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @literA2

          var currentItem = stack.pop()
          ...
          currentItem.mySignal.connect(onMySignal)
          
          //mySignal is the signal in currentItem
          //onMySignal is a JS function
          

          157

          L 1 Reply Last reply
          0
          • p3c0P p3c0

            @literA2

            var currentItem = stack.pop()
            ...
            currentItem.mySignal.connect(onMySignal)
            
            //mySignal is the signal in currentItem
            //onMySignal is a JS function
            
            L Offline
            L Offline
            literA2
            wrote on last edited by
            #5

            @p3c0 Thank you very much! Please considered this SOLVED!

            1 Reply Last reply
            0
            • L literA2

              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.

              J Offline
              J Offline
              jxgeoffrey
              wrote on last edited by
              #6

              @literA2 how does Page1.qml has access to mainStack? I need this functionality in my app too. Navigation within the stackview pages.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved