Hi all,

I'm stumped trying to understand why I my QTableWidget to scroll like I think it should. I'm appending rows to a QTableWidget and I want to center the view on a particular row.

Qt Code:
  1. ui->tableWidget->scrollToTop();
  2. ui->tableWidget->scrollToBottom();
To copy to clipboard, switch view to plain text mode 

Testing one at a time, both of these work great and the behavior is as expected. The scrollbars\view stay either at the top or the bottom. However when I try to center the view it doesn't work at all:

Qt Code:
  1. ui->tableWidget->scrollToItem(ui->tableWidget->itemAt(center, 0));
To copy to clipboard, switch view to plain text mode 

Center is an integer representing the row I want to center the view on. I tried switching "center,0" with "0,center" it didn't seem to help. I check the return value for itemAt and it's returning a non-NULL value.

My workaround (from: "QListWidget in a tab not scrolling on setCurrentRow()") was to do this:

Qt Code:
  1. ui->tableWidget->setCurrentCell(center, 0);
  2. QModelIndex index = ui->tableWidget->currentIndex();
  3. ui->tableWidget->scrollTo(index, QAbstractItemView::PositionAtCenter);
  4. ui->tableWidget->setCurrentCell(-1, -1);
To copy to clipboard, switch view to plain text mode 

Which works but seems horrible. The last setCurrentCell() was to un-highlight the cell...

For my own knowledge can you please help to explain what I was doing wrong? Thanks in advance.