last line core dump from QSqlTableModel/QTableView

28 Views Asked by At

I am using PySide6 QSqlTableModel and QTableView to display a table in a QSqlDatabase. I capture QEvent.ToolTip and massage the data to retrieve the contents of a cell which my mouse cursor has entered.

Here is the relevant code snippet:

def eventFilter(self, watched, e):
    if e.type() == QEvent.ToolTip:
        row = self.table.rowAt(e.pos().y())
        col = self.table.columnAt(e.pos().x())
        modelindex = self.model.index(row-1, col)
        # In the model, row and column are both 0-origin, but in
        # this code, a row adjustment is made because one row is
        # used by the column headers.


There are 8922 rows in the table, which is confirmed by the listing and self.model.rowCount().

Everything works perfectly, exactly the way I want, except for the last row. When the last row in the viewport is 8922 and I place my cursor over a cell of that row, the above code returns row == -1. This is not some kind of off-by-one error; when I place the cursor over row 8921, the code returns row == 8921. For (model) row 1, it returns row == 1, etc. (Note that reported row numbers are higher by one because of the header row. The columns return as 0-origin.) Only the last row is a problem.

It also has nothing to do with the last line of the viewport. If the viewport is displaying some other part of the table, the system is well-behaved if I put the cursor on the last line displayed.

Also, the row 8922 situation results in a segmentation fault core dump. Analyzing core dumps is a tad above my pay grade, and since I've spent weeks getting this code working, I'm not anxious to learn it, but if I hafta, I hafta.

Any help will garner my undying gratitude.

0

There are 0 best solutions below