Each QtableView has a Selection model. For each of the two QtableViews you can connect the signal currentChanged of the selection model to a slot change the selection of the other QtableView by setCurrentIndex. This can be done like:
QObject::connect(ui->tableView1->selectionModel(),SIGNAL(currentChanged(QModelIndex,QModelIndex)),this,SLOT(onCurrentChanged1(QModelIndex,QModelIndex)));
QObject::connect(ui->tableView2->selectionModel(),SIGNAL(currentChanged(QModelIndex,QModelIndex)),this,SLOT(onCurrentChanged2(QModelIndex,QModelIndex)));
void MyClass::onCurrentChanged1(QModelIndex curIndex, QModelIndex prevIndex)
{
int newRow = curIndex.row();
int curRow = ui->tabaleView2->selectionModel()->currentIndex().row();
if( newRow != curRow )
{
QModelIndex newIndex = ui->tabaleView2->model()->index(row, 0);
ui->tabaleView2->setCurrentIndex(newIndex);
}
}
void MyClass::onCurrentChanged2(QModelIndex curIndex, QModelIndex prevIndex)
{
int newRow = curIndex.row();
int curRow = ui->tabaleView1->selectionModel()->currentIndex().row();
if( newRow != curRow )
{
QModelIndex newIndex = ui->tabaleView1->model()->index(row, 0);
ui->tabaleView1->setCurrentIndex(newIndex);
}
}