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. ContentX in ListView switches back to 0 when model is updated.
Forum Updated to NodeBB v4.3 + New Features

ContentX in ListView switches back to 0 when model is updated.

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 3 Posters 677 Views 2 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.
  • A Offline
    A Offline
    Anita
    wrote on last edited by
    #1

    Hi,

    I have a tableView and a ListView in my qml.
    The ContentX of the ListView is mapped to the contentX of the tableview.

    But when the model is updated , even though the contentX of tableview comes a positive number, the contentX of the Listview switches back to 0.

    Is there a different solution where i can match the contentX of the List view to the contentX of the TableView ?

    J.HilkJ ODБOïO 2 Replies Last reply
    0
    • A Anita

      Hi,

      I have a tableView and a ListView in my qml.
      The ContentX of the ListView is mapped to the contentX of the tableview.

      But when the model is updated , even though the contentX of tableview comes a positive number, the contentX of the Listview switches back to 0.

      Is there a different solution where i can match the contentX of the List view to the contentX of the TableView ?

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Anita very hard to tell without knowing how exactly you do this. Can you show your code?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • A Anita

        Hi,

        I have a tableView and a ListView in my qml.
        The ContentX of the ListView is mapped to the contentX of the tableview.

        But when the model is updated , even though the contentX of tableview comes a positive number, the contentX of the Listview switches back to 0.

        Is there a different solution where i can match the contentX of the List view to the contentX of the TableView ?

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by ODБOï
        #3

        @Anita hi
        the ListView doc says
        It is not recommended to use contentX or contentY to position the view at a particular index. This is unreliable since removing items from the start of the list does not cause all other items to be repositioned, and because the actual start of the view can vary based on the size of the delegates.

        Try to use positionViewAtIndex method

        A 1 Reply Last reply
        0
        • A Offline
          A Offline
          Anita
          wrote on last edited by
          #4

          @J-Hilk
          Hi,
          I cannot post the code, but the requirement is such as follows:

          1. The List View is horizontally oriented which is placed below the table view.
          2. The width of the List View and the tableView is the same.
          3. The No. of coloumns of the tableview is same as the no of elements in the List view.
          4. The width of each of the column of the table view is the same as that of the delegate width of the List View.
          5. The List view is not interactive.
          6. The List View should be synched with the horizontal movement of the tableview.

          All of these requirements where achieved , and the 4th requirement is achieved by managing the contentX of the listview maching the contentX of the tableview.

          But when a new entry is added in the model of the tableview and the ListView, the contentX of the Listview switches back to 0 even if the contentX of the tableview is a positive no.

          1 Reply Last reply
          0
          • ODБOïO ODБOï

            @Anita hi
            the ListView doc says
            It is not recommended to use contentX or contentY to position the view at a particular index. This is unreliable since removing items from the start of the list does not cause all other items to be repositioned, and because the actual start of the view can vary based on the size of the delegates.

            Try to use positionViewAtIndex method

            A Offline
            A Offline
            Anita
            wrote on last edited by
            #5

            @LeLev
            Hi LeLev,

            The issue is I have to synch the tableview and the ListView positions.
            So if we scroll the tableview, the listview also should scroll. So In that case i will need to know the index of the tableview as well. as i wouldnt know the current Index of the TableView.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Anita
              wrote on last edited by Anita
              #6

              Hi @J-Hilk, @LeLev

              Code is Similar to the following :
              TableView {
              id:tableview
              width: 500
              height:200
              columnWidthProvider: 50
              rowHeightProvider: 20
              model:TableModel
              delegate:
              Rectangle {
              width : 50
              height : 20
              Text {
              width: 55
              height: 40
              text: tabledataText
              }
              }
              .
              .
              .

              }
              ListView {
              id:listview
              x: 0
              y:250
              contentX: tableview.contentX
              orientation: ListView.Horizontal
              model : tableview.columns>0 ? tableview.columns:1
              delegate:
              Rectangle{
              id: listdelegate
              width :50
              height: 25
              Text{
              anchors.fill: listdelegate
              text: tableview.headerData(data,Qt.Horizontal)
              }
              }
              }

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Anita
                wrote on last edited by Anita
                #7

                Hi @J-Hilk @LeLev

                If I put the problem statement in other words:

                I need to synch the horizontal movement of the ListView with the TableView .
                The Listview is not interactable. Is there any other method other than having contentX matched.?

                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