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. TableView positionViewAtRow
Qt 6.11 is out! See what's new in the release blog

TableView positionViewAtRow

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 494 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.
  • rincewindR Offline
    rincewindR Offline
    rincewind
    wrote on last edited by
    #1

    Hi

    I don't understand how to use the positionViewAtRow function to position a TableView on the last row. The documentation is a bit sparse on the parameters introduced in Qt 6.

    No matter what I try, I get a crash.

    TableView {
                id: tableView
    
                model: dataModel
    
                Component.onCompleted: {
                    let lastRow = dataModel.rowCount - 1;
                    console.log(`lastRow: ${lastRow}`);
                    positionViewAtRow(lastRow, TableView.Contain, 0, Qt.rect(0, 0, 0, 0))
                }
    
    }
    
    rincewindR 1 Reply Last reply
    0
    • rincewindR rincewind

      Hi

      I don't understand how to use the positionViewAtRow function to position a TableView on the last row. The documentation is a bit sparse on the parameters introduced in Qt 6.

      No matter what I try, I get a crash.

      TableView {
                  id: tableView
      
                  model: dataModel
      
                  Component.onCompleted: {
                      let lastRow = dataModel.rowCount - 1;
                      console.log(`lastRow: ${lastRow}`);
                      positionViewAtRow(lastRow, TableView.Contain, 0, Qt.rect(0, 0, 0, 0))
                  }
      
      }
      
      rincewindR Offline
      rincewindR Offline
      rincewind
      wrote on last edited by
      #2

      OK, it seems you have to delay the positionViewAtRow call until the model data is loaded.

      Timer {
              id: positionTimer
              interval: 100
              running: false
              repeat: true
              onTriggered: {
                  if (dataModel.rowCount > 0) {
                      tableView.positionViewAtRow(dataModel.rowCount - 1, TableView.Contain, 0, Qt.rect(0, 0, 0, 0));
                      running = false;
                  }
              }
          }
      

      And activate it.

      TableView {
                  id: tableView
      
                  model: dataModel
      
                  Component.onCompleted: positionTimer.running = true 
      }
      
      1 Reply Last reply
      0
      • rincewindR rincewind has marked this topic as solved on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved