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. Prgramatically set ScrollView's position
Forum Updated to NodeBB v4.3 + New Features

Prgramatically set ScrollView's position

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 3.7k 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.
  • D Offline
    D Offline
    DBoosalis
    wrote on last edited by A Former User
    #1

    I have a ListView inside a Scrollview. When the user clicks on an item it brings up a dialog to edit a value. When the user hits save the data gets saved in C++ where endResetModel gets called which causes the item in the QML Listview to get updated. So far so good, but what happens is that the ScrooView goes back to the top. I have tried eveything I can think of to set the ScrollView to the proper position but nothing works. Can anyone please give me advise on how to move scrollbar. Here is some of my code:

    onValueChanged:  {
      if (manageInventoryPage.restoreYPosition) {
        // get this 
        console.log("restore position to:  + lastYPosition) 
        mylistview.contentY = lastYPosition;
        restoreYPosition = false;
        myScrollView.flickableItem.contentY = lastYPosition
      }
    }
    

    Edit: wrapped code with backticks -- @Wieland

    1 Reply Last reply
    0
    • jpnurmiJ Offline
      jpnurmiJ Offline
      jpnurmi
      wrote on last edited by
      #2

      Is it absolutely necessary to reset the whole model? Reseting a model means that the view gets re-built from scratch. The view can only retain the scrolling position if you modify the model so that you insert, remove, or change data.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DBoosalis
        wrote on last edited by
        #3

        Thanks for the reply. I found that if I did not do beginResetModel and endResetModel in my model that inherrits from QAbstractListModel, I find that the updates do not show up at all in the QML. Do you know of another way to get the updates into my QML.

        Thanks again for taking the time to reply

        jpnurmiJ 1 Reply Last reply
        0
        • D DBoosalis

          Thanks for the reply. I found that if I did not do beginResetModel and endResetModel in my model that inherrits from QAbstractListModel, I find that the updates do not show up at all in the QML. Do you know of another way to get the updates into my QML.

          Thanks again for taking the time to reply

          jpnurmiJ Offline
          jpnurmiJ Offline
          jpnurmi
          wrote on last edited by jpnurmi
          #4

          If you change the data of existing items, emit dataChanged(). If you insert new row(s), call beginInsertRows() before inserting new rows into the data structure, and endInsertRows() immediately afterwards. If you remove row(s), call beginRemoveRows() before removing old rows from the data structure, and endRemoveRows() immediately afterwards.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DBoosalis
            wrote on last edited by
            #5

            Thank you for the vital lesson on how to properly update items in a QML ListView from C++, the dataChanged signal worked like a charm with no other code necessary in the QML.

            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