Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QML ListView: error when change width of delegate

    QML and Qt Quick
    2
    3
    182
    Loading More Posts
    • 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.
    • J
      Jane Sully last edited by Jane Sully

      Hi all,
      I want to create a list of item and the current item is bigger than others but i have an issue.
      When I flick the list so the first item is hidden and click on other item to change current index of listview, the contentX of listview is wrong. This only occur when the current index is 0
      More detail of what I do to test:

      • Current index is 0
      • Flick to the end of list and click on an item to change current index
      • Flick back to the begin and console.log(listView.contentX) => output 40 when it's suppose to output 0

      Anyone know how to fix this? I need to use contentX for another purpose.
      Here's my code:

      ListView{
              id:listView
              width: 1000; height:700
              orientation: ListView.Horizontal
              cacheBuffer: 20000
              spacing: 10
              model:15
              delegate: Rectangle{
                  id:baseDele
                  width: index == listView.currentIndex ? 120 : 100
                  height: 500
                  border.width: 1
                  Text {
                      anchors.centerIn: parent
                      text:index
                  }
                  MouseArea{
                      anchors.fill: parent
                      onPressed: listView.currentIndex = index
                      onReleased: console.log(listView.contentX)
                      
                  }
              }
          }
      
      1 Reply Last reply Reply Quote 0
      • GrecKo
        GrecKo Qt Champions 2018 last edited by

        You need to use originX too.

        listView.contentX + listView.originX should be 0.

        1 Reply Last reply Reply Quote 0
        • J
          Jane Sully last edited by

          I try what you suggest but originX and contentX is the same

          1 Reply Last reply Reply Quote 0
          • First post
            Last post