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 take index of element StackView in QML ?
Forum Update on Monday, May 27th 2025

How to take index of element StackView in QML ?

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 2.2k 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.
  • M Offline
    M Offline
    mrbongdem
    wrote on 30 Aug 2015, 17:08 last edited by
    #1

    Hi, everyone

    I need determine index of each element in StackView in QML.
    Can anyone explain for me ?

    Thanks.

    P 1 Reply Last reply 31 Aug 2015, 05:01
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 30 Aug 2015, 20:43 last edited by
      #2

      Hi and welcome to devnet,

      Isn't the StackView Finding Items Chapter what you are looking for ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M mrbongdem
        30 Aug 2015, 17:08

        Hi, everyone

        I need determine index of each element in StackView in QML.
        Can anyone explain for me ?

        Thanks.

        P Offline
        P Offline
        p3c0
        Moderators
        wrote on 31 Aug 2015, 05:01 last edited by
        #3

        Hi @mrbongdem
        Also in addition to @SGaist's answer StackView too has a few attached properties and index is one of them. Check supported-attached-properties.

        157

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrbongdem
          wrote on 5 Sept 2015, 15:36 last edited by
          #4

          Thank you for your help !!!
          I solved it by add property **index ** for each element in ListModel.

          P 1 Reply Last reply 6 Sept 2015, 08:28
          0
          • M mrbongdem
            5 Sept 2015, 15:36

            Thank you for your help !!!
            I solved it by add property **index ** for each element in ListModel.

            P Offline
            P Offline
            p3c0
            Moderators
            wrote on 6 Sept 2015, 08:28 last edited by
            #5

            @mrbongdem Thats great. But how did you use ListModel with StackView ? You can directly get index using Stack.index inside the item without creating a new property.

            157

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrbongdem
              wrote on 6 Sept 2015, 09:15 last edited by mrbongdem 9 Jun 2015, 09:16
              #6

              Hi @p3c0
              I use this way :

               StackView {
                       id: stackView
                       initialItem: ListView {
              	     model: rssFeeds
              		 delegate: Button{
              	     onClicked: {
              			// at here I take index .It is property of ListModel rssFeeds	
              		 }
                      }
              	
                    }
                   }
              

              And How do you use Stack.index .Can you give me example for it ?
              Thank you for your replay.

              P 1 Reply Last reply 6 Sept 2015, 10:01
              0
              • M mrbongdem
                6 Sept 2015, 09:15

                Hi @p3c0
                I use this way :

                 StackView {
                         id: stackView
                         initialItem: ListView {
                	     model: rssFeeds
                		 delegate: Button{
                	     onClicked: {
                			// at here I take index .It is property of ListModel rssFeeds	
                		 }
                        }
                	
                      }
                     }
                

                And How do you use Stack.index .Can you give me example for it ?
                Thank you for your replay.

                P Offline
                P Offline
                p3c0
                Moderators
                wrote on 6 Sept 2015, 10:01 last edited by
                #7

                @mrbongdem Ok so you have StackView which contains ListView in which you wanted index. I imagined something different from your original question.
                Anyway ListView has index attached property. So no need of creating another index property. Eg.

                ListView {
                    model: ListModel {
                        Component.onCompleted: {
                            for(var a=10; a<15; a++)
                                append( { name: "Item: " + a })
                        }
                    }
                    delegate: Text {
                        text: name + " with Index: " + index //index = attached property
                    }
                }
                

                157

                1 Reply Last reply
                0

                1/7

                30 Aug 2015, 17:08

                • Login

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