I am working on a small proof of concept with PyQT5: A simple database query tool based on QTableView widget and SQLite database. So far, I can get basic connectivity to the database, display rows, sort by columns, etc. So far, so good!
The thing where I got stuck is: a) I'd like to be able to read the values from whatever the "current row" is in UI, the one the cursor is currently on b) I'd like to be able to capture the navigation from one row to another (e.g. scrolling) and do something with it, e.g. change a separateQLineEdit field to the current row's Comment field value (just an example)
EDIT: Clarifying the use case
- The user scrolls through the records, either by pressing keys or clicking with a mouse.
- When a "Delete" button is pressed, whatever the current row is will be marked for deletion
The parts I am struggling with are:
a) How to trigger / connect signal when "keys" (up arrow, down arrow) are used to navigate. Mouse-clicks work just fine (using signal "Entered" from QTableView (inherited from QAbstractItemView)
b) Clicking on the row number (#2 in the attached screenshot), does not seem to generate any signal that can be captured / processed, e.g. in order to remove this particular row, if desired so
Yay, I figured it out :-) thanks to this post: Basically, any navigation seems to generate "selectionChanged" signal in selectionModel object. So, one of the solutions how to capture the current row, while navigating through the table is to get the selectionModel object from underlying QTableView object and then connect to the signal selectionChanged, e.g.
(transactions is QTableView object, selection_changed is the custom method I created to handle what happens when a selection is changed, which also includes navigating from one row to another, which was the original objective)