I have two QTableViews that share a QSqlQueryModel set as their model. I have deliberately hidden some rows in each, based on the value of a column in the QSqlQueryModel, as in the example as follows:
for (int i = 0; i < model->rowCount(); i++) {
bool assigned = model->record(i).value(0).toBool();
if (assigned) {
// Hide from available options
ui->available_tableview->setRowHidden(i, true);
} else {
// Hide from assigned list
ui->assigned_tableview->setRowHidden(i, true);
}
}
for (int i = 0; i < model->rowCount(); i++) {
bool assigned = model->record(i).value(0).toBool();
if (assigned) {
// Hide from available options
ui->available_tableview->setRowHidden(i, true);
} else {
// Hide from assigned list
ui->assigned_tableview->setRowHidden(i, true);
}
}
To copy to clipboard, switch view to plain text mode
This all works fine, until I scroll either table (they are in the same MainWindow) and then all of the rows that are hidden in the assigned_tableview show up again. Oddly, the rows that are hidden in the available_tableview stay hidden. I have tried using two different models, and they same behavior occurred. I also tried emitting layoutChanged() from the model, as recommended by this answer, but the behavior remained. Any ideas on what might be causing this behavior?
Added after 1 41 minutes:
Okay, so on my drive home I think I realized what the issue is. The QSqlQueryModel is only loading the first 256 results by default, so when I scroll it loads more. I'm not actually seeing rows that I have hidden reappear, I am seeing rows that weren't previously loaded appear. If I fetch all the results before setting the model, this issue *should* go away. I have to wait until I'm back at my work machine tomorrow to confirm, but I wanted to post this here so people didn't waste time answer a question that I think I have an answer to. Couldn't figure out how to delete the question!
Bookmarks