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. ListView and PageIndicator - PageIndicator is not updated
QtWS25 Last Chance

ListView and PageIndicator - PageIndicator is not updated

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qml dynamicpageindicatorlistview flicklistview
5 Posts 3 Posters 2.5k 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.
  • B Offline
    B Offline
    BjoernK
    wrote on 8 Dec 2017, 09:52 last edited by
    #1

    Hi everyone.

    I encountered a little problem with a ListView interacting with a PageIndicator.
    The ListView is populated with items from a ListModel which holds image sources.
    The ListView displays the images correctly and the PageIndicator shows "bullets" which represent the images. If one clicks on such a bullet then the ListView scrolls to the corresponding image. But if one flicks to another image by means of the ListView then the PageIndicator is not updated - meaning that the PageIndicator does not highlight the bullet representing the newly selected image.

    Can anyone tell me if I missed to set a certain property?

    Here is a code excerpt which shows how I used the ListView and PageIndicator:

            ListView {
                id: listView
                anchors.fill: parent
                orientation: Qt.Horizontal
                model: ListModel {
                     id: listModel
                }
                focus: true
                snapMode: ListView.SnapOneItem
                currentIndex: pageIndicator.currentIndex
                PageIndicator {
                    id: pageIndicator
                    currentIndex: listView.currentIndex
                    count: listView.count
                    interactive: true
                    anchors.bottom: parent.bottom
                    anchors.horizontalCenter: parent.horizontalCenter
                }
                delegate: Component {
                    Item {
                        width: listView.width
                        height: listView.height
                        Image {
                            source: sourceImage
                            width: parent.width
                            height: parent.height
                            smooth: true
                            fillMode: Image.PreserveAspectFit
                            verticalAlignment: Image.AlignVCenter
                        }
                    }
                }
            }
    

    Best regards,
    Björn

    1 Reply Last reply
    0
    • J jpnurmi
      10 Dec 2017, 12:47

      The bindings are fine. The problem is that the ListView has only snapMode set, but highlightRangeMode seems to be missing. Therefore the ListView is not changing its currentIndex while flicking.

      snapMode does not affect the currentIndex. To update the currentIndex as the list is moved, set highlightRangeMode to ListView.StrictlyEnforceRange.

      https://doc-snapshots.qt.io/qt5-5.9/qml-qtquick-listview.html#snapMode-prop

      B Offline
      B Offline
      BjoernK
      wrote on 30 Dec 2017, 23:25 last edited by
      #5

      @jpnurmi said in ListView and PageIndicator - PageIndicator is not updated:

      The bindings are fine. The problem is that the ListView has only snapMode set, but highlightRangeMode seems to be missing. Therefore the ListView is not changing its currentIndex while flicking.

      snapMode does not affect the currentIndex. To update the currentIndex as the list is moved, set highlightRangeMode to ListView.StrictlyEnforceRange.

      https://doc-snapshots.qt.io/qt5-5.9/qml-qtquick-listview.html#snapMode-prop

      Thank you @jpnurmi.
      The following line solved the problem:

      highlightRangeMode: ListView.StrictlyEnforceRange
      

      Somehow I missed another thread: https://forum.qt.io/topic/81429/listview-does-not-change-currentindex-when-scrolling/6

      Best regards,
      Björn

      1 Reply Last reply
      0
      • O Offline
        O Offline
        ODБOï
        wrote on 8 Dec 2017, 11:57 last edited by
        #2

        Hello @BjoernK !
        I think you did some bad bindings :
        PageIndicator {
        currentIndex: listView.currentIndex
        }
        ListView {
        currentIndex: pageIndicator.currentIndex
        }
        Im not sur this is looking like a binding loop, correct me if im wrong

        maybe you can create a property int _index
        and then use it to set the same index on your list & PageIndicator

        PageIndicator {
        currentIndex: _index
        }
        ListView {
        currentIndex: _index
        }

        1 Reply Last reply
        0
        • B Offline
          B Offline
          BjoernK
          wrote on 8 Dec 2017, 17:50 last edited by
          #3

          Hi!

          Thank you for your reply.

          I think the binding of the currentIndex-properties is correct. The following example can be found in the Qt docs:

          SwipeView {
              id: view
              currentIndex: pageIndicator.currentIndex
              anchors.fill: parent
          
              Page {
                  title: qsTr("Home")
              }
              Page {
                  title: qsTr("Discover")
              }
              Page {
                  title: qsTr("Activity")
              }
          }
          
          PageIndicator {
              id: pageIndicator
              interactive: true
              count: view.count
              currentIndex: view.currentIndex
          
              anchors.bottom: parent.bottom
              anchors.horizontalCenter: parent.horizontalCenter
          }
          

          I'm currently using Qt 5.9.1. I'm going to install Qt 5.9.3. Maybe it works then.

          Best regards,
          Björn

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jpnurmi
            wrote on 10 Dec 2017, 12:47 last edited by jpnurmi 12 Oct 2017, 12:47
            #4

            The bindings are fine. The problem is that the ListView has only snapMode set, but highlightRangeMode seems to be missing. Therefore the ListView is not changing its currentIndex while flicking.

            snapMode does not affect the currentIndex. To update the currentIndex as the list is moved, set highlightRangeMode to ListView.StrictlyEnforceRange.

            https://doc-snapshots.qt.io/qt5-5.9/qml-qtquick-listview.html#snapMode-prop

            B 1 Reply Last reply 30 Dec 2017, 23:25
            1
            • J jpnurmi
              10 Dec 2017, 12:47

              The bindings are fine. The problem is that the ListView has only snapMode set, but highlightRangeMode seems to be missing. Therefore the ListView is not changing its currentIndex while flicking.

              snapMode does not affect the currentIndex. To update the currentIndex as the list is moved, set highlightRangeMode to ListView.StrictlyEnforceRange.

              https://doc-snapshots.qt.io/qt5-5.9/qml-qtquick-listview.html#snapMode-prop

              B Offline
              B Offline
              BjoernK
              wrote on 30 Dec 2017, 23:25 last edited by
              #5

              @jpnurmi said in ListView and PageIndicator - PageIndicator is not updated:

              The bindings are fine. The problem is that the ListView has only snapMode set, but highlightRangeMode seems to be missing. Therefore the ListView is not changing its currentIndex while flicking.

              snapMode does not affect the currentIndex. To update the currentIndex as the list is moved, set highlightRangeMode to ListView.StrictlyEnforceRange.

              https://doc-snapshots.qt.io/qt5-5.9/qml-qtquick-listview.html#snapMode-prop

              Thank you @jpnurmi.
              The following line solved the problem:

              highlightRangeMode: ListView.StrictlyEnforceRange
              

              Somehow I missed another thread: https://forum.qt.io/topic/81429/listview-does-not-change-currentindex-when-scrolling/6

              Best regards,
              Björn

              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