QTableView clicked.connect() keyboard scroll equivalent in PyQt5

sK500 :

I have the following method in some ui i'm working on:

def get_employees(self):
    self.employee_frame = pd.read_sql_query('SELECT * FROM emp_data', self.connection)
    model = PandasModel(self.employee_frame.drop('image', axis=1))
    self.employee_data.setModel(model)
    self.employee_data.setSelectionBehavior(QAbstractItemView.SelectRows)
    self.employee_data.clicked.connect(self.display_selected)

Whenever I click on a table row in the right part of the screen, details in the left part are displayed and changed according to the selected row. What is the equivalent that makes the details change also by scrolling up and down the QTableView rows?

Here's how it looks:

ui

eyllanesc :

You must use the currentChanged signal of the QItemSelectionModel associated with the QTableView and the model (with this change it is not necessary to use the clicked signal):

def get_employees(self):
    self.employee_frame = pd.read_sql_query('SELECT * FROM emp_data', self.connection)
    model = PandasModel(self.employee_frame.drop('image', axis=1))
    self.employee_data.setModel(model)
    self.employee_data.setSelectionBehavior(QAbstractItemView.SelectRows)
    self.employee_data.selectionModel().currentChanged.connect(self.display_selected)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=12583&siteId=1