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 know "y" property of an Item when it is created in a ListView
Forum Updated to NodeBB v4.3 + New Features

How to know "y" property of an Item when it is created in a ListView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 1.4k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    Fheanor
    wrote on last edited by Fheanor
    #1

    I use a ListView and I need to fill my Window with the last Item that was inserted inside it.
    In this case, I set the ListView property: contentY with the y value of myItem

    My problem is that when you insert a new Item, I don't know how to know the y value of the Item because it is not yet set.

    This is what I try:

    ScrollView {
        id: scroll
        ListView {
            model: DelegateModel {
                id: visualModel
                model: myModel //Model is set in the cpp
                delegate: Rectangle {
                    id: rectangleDelegate
    
                    Component.onCompleted: {
                       rectangleDelegate.ListView.view.contentY = rectangleDelegate.y
                       console.log(rectangleDelegate.y ) //Not set yet (y = 0)
                    }
    
                    Button {
                        onClicked { 
                            rectangleDelegate.ListView.view.contentY = rectangleDelegate.y
                            console.log(rectangleDelegate.y ) //Now it is ok (y = rightValue)
                        }
                    }
                }
            }
        }
    }   
    

    How could I proceed ?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Which item addRoot refers to?

      (Z(:^

      F 1 Reply Last reply
      0
      • sierdzioS sierdzio

        Which item addRoot refers to?

        F Offline
        F Offline
        Fheanor
        wrote on last edited by
        #3

        @sierdzio said in How to know "y" property of an Item when it is created in a ListView:

        Which item addRoot refers to?

        I updated my code, it was a mistake

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Thanks, now it's more clear.

          Have you tried using positionViewAtIndex? Looks like just what might suit your needs.

          (Z(:^

          F 1 Reply Last reply
          1
          • sierdzioS sierdzio

            Thanks, now it's more clear.

            Have you tried using positionViewAtIndex? Looks like just what might suit your needs.

            F Offline
            F Offline
            Fheanor
            wrote on last edited by
            #5

            @sierdzio This is exactly what I need, thanks !

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Great, happy coding :-)

              (Z(:^

              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